import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
int first, second, add, subtract, multiply;
float devide;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Two Numbers : ");
first = scanner.nextInt();
second = scanner.nextInt();
add = first + second;
subtract = first - second;
multiply = first * second;
devide = (float) first / second;
System.out.println("Sum = " + add);
System.out.println("Difference = " + subtract);
System.out.println("Multiplication = " + multiply);
System.out.println("Division = " + devide);
}
}
Enter Two Numbers : 12
5
Sum = 17
Difference = 7
Multiplication = 60
Division = 2.4
This Java program asks the user to provide integer inputs to perform mathematical operations.
1. Scanner class and its functions are used to obtain inputs, and println() function is used to print on the screen.
2. Scanner class is a part of java.util package, so we required to import this package in our Java program.
3. We also required to create a object of Scanner class to call its functions.