Create a program that reads two integers, a and b, from the user.Your program should compute and display:
A) The sum of a and b
B)The difference when b is subtracted from a
C)The product of a 1311110069and b D)The quotient when a is divided by b
E)The remainder when a is divided by b
F)The result of log10 a
G)The result of ab
Hint: You will probably find the log10 function in the math module helpful
for computing the second last item in the list.
5
2
Output:
The addition of 5 and 2 is 7
The subtraction of 5 and 2 is 3
The product of 5 and 2 is 10
The division of 5 and 2 is 2
The remainder of 5 and 2 is 1
The 5 ^ 2 is 25
12
5
The addition of 12 and 5 is 17
The subtraction of 12 and 5 is 7
The product of 12 and 5 is 60
The division of 12 and 5 is 2
The remainder of 12 and 5 is 2
The 12 ^ 5 is 248832
38
4
The addition of 38 and 4 is 42
The subtraction of 38 and 4 is 34
The product of 38 and 4 is 152
The division of 38 and 4 is 9
The remainder of 38 and 4 is 2
The 38 ^ 4 is 2085136
12
3
The addition of 12 and 3 is 15
The subtraction of 12 and 3 is 9
The product of 12 and 3 is 36
The division of 12 and 3 is 4
The remainder of 12 and 3 is 0
The 12 ^ 3 is 1728
Tags JAVA languagesSubscribe Our Newsletter
import java.io.*;
ReplyDeleteimport java.util.Scanner;
public class TestClass {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num1 = in.nextInt();
int num2 = in.nextInt();
System.out.println("The addition of " + num1 + " and " + num2 + " is " +
(num1 + num2));
System.out.println("The subtraction of " + num1 + " and " + num2 + " is " +
(num1 - num2));
System.out.println("The product of " + num1 + " and " + num2 + " is " +
(num1 * num2));
System.out.println("The division of " + num1 + " and " + num2 + " is " +
(num1 / num2));
System.out.println("The remainder of " + num1 + " and " + num2 + " is " +
(num1 % num2));
System.out.println("The " + num1 + " ^ " + num2 + " is " + ((int)Math.pow(num1,num2)));
}
}