Question: Write an application that asks the user to enter two integers, obtains them from the user and prints the square of each, the sum of
Write an application that asks the user to enter two integers, obtains them from the user and prints the square of each, the sum of their squares, and the difference of the squares (first number squared minus the second number squared). Use the techniques shown in Fig. 2.7.
Fig. 2.7

1 // Fig. 2.7: Addition.java 2 // Addition program that inputs two numbers then displays their sum. 3 import java.util.Scanner; // program uses class Scanner 1234 4 5 public class Addition { 6 7 8 9 10 [I 12 13 14 15 16 17 18 19 20 21 // main method begins execution of Java application public static void main (String[] args) { // create a Scanner to obtain input from the command window Scanner input = new Scanner (System.in); System.out.print("Enter first integer: "); // prompt int number1 = input.nextInt(); // read first number from user System.out.print("Enter second integer: "); // prompt int number2 = input.nextInt(); // read second number from user int sum = numberl + number2; // add numbers, then store total in sum System.out.printf("Sum is %d %n", sum); // display sum } // end method main } // end class Addition
Step by Step Solution
3.35 Rating (164 Votes )
There are 3 Steps involved in it
The code youve shown in the image is an example program that takes in two integers from the user and prints out their sum To write an application that ... View full answer
Get step-by-step solutions from verified subject matter experts
