Write a program in Java to print the multiplication and division of two numbers (Let x = 100, y = 5 assign the values)
Answers
Explanation:
import java.util.Scanner;
public class Exercise6 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input first number: ");
int num1 = in.nextInt();
System.out.print("Input second number: ");
int num2 = in.nextInt();
System.out.println(num1 + " + " + num2 + " = " +
(num1 + num2));
System.out.println(num1 + " - " + num2 + " = " +
(num1 - num2));
System.out.println(num1 + " x " + num2 + " = " +
(num1 * num2));
System.out.println(num1 + " / " + num2 + " = " +
(num1 / num2));
System.out.println(num1 + " mod " + num2 + " = " +
(num1 % num2));
}
}
Note :
Please check the attachment given below to see the compilation of the code mentioned.
Program :
import java.util.Scanner;
public class Something
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the elements :");
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a*b);
System.out.println(a/b);
}
}
Input :
100
5
Output :
500
20
Hope it helps. If yes, leave a smile. :)