2.20 TEST 2: the worst calculator ever Input
Prompt the user for 2 integers. Enter an integer: 5 Enter another integer: 2 Processing Modify the first integer by adding 1 to it and save the new value into a variable called modified_int1. Modify the second integer by subtracting 1 from it and save the new value into a variable called modified_int2. Compute the sum, difference, product, quotient, and exponentiation of modified_int1 and modified_int2 and save each into a variable. Print a warning message informing the user that this calculator is not to be trusted. Print the original numbers, the operations, and the new results (as shown below).
Output
Enter an integer: 5
Enter another integer: 2
WARNING: These results are probably wrong!!!
5 + 2 = 7
5 - 2 = 5
5 * 2 = 6
5 / 2 = 6
5 ^ 2 = 6
WorstCalculator.java
import java.util.Scanner;
public class WorstCalculator {
public static void main(String[] args) {
// Scanner class object to get the
input from user
Scanner input=new
Scanner(System.in);
System.out.print("Enter an integer:
");
int integer1=input.nextInt(); //
accept first integer
System.out.print("Enter another
integer: ");
int integer2=input.nextInt(); //
accept second integer
// Modify the first integer by
adding 1 to it
// and save the new value into a
variable called modified_int1
int modified_int1=integer1+1;
// Modify the second integer by
subtracting 1 from it
// and save the new value into a
variable called modified_int2
int modified_int2=integer2-1;
System.out.println("\nWARNING:
These results are probably wrong!!!");
// calculate and print
results
System.out.println(integer1+" +
"+integer2+" = "+(modified_int1+modified_int2));
System.out.println(integer1+" -
"+integer2+" = "+(modified_int1-modified_int2));
System.out.println(integer1+" *
"+integer2+" = "+(modified_int1*modified_int2));
System.out.println(integer1+" /
"+integer2+" = "+(modified_int1/modified_int2));
System.out.println(integer1+" ^
"+integer2+" = "+((int)Math.pow(modified_int1,
modified_int2)));
input.close(); // close Scanner
object
}
}
Sample run 1
Sample run 2
Note--> If you want this solution in any other programming language then comment below....
Get Answers For Free
Most questions answered within 1 hours.