/* Adder2.java - This is the same adder program, except that this time, * we ask the user for the two numbers to add. */ import java.util.Scanner; // include built-in Scanner class for input public class Adder2 { public static void main(String [] args) { // Step 1 -- Get input. Ask user to enter 2 numbers, and read them in. // Tell computer we want to use a Scanner, and that we want to // be able to "scan" the keyboard input, which Java calls System.in. Scanner sc = new Scanner(System.in); System.out.printf ("Please enter first number: "); int first = sc.nextInt(); System.out.printf ("Please enter second number: "); int second = sc.nextInt(); // Step 2 -- Perform calculations. int sum = first + second; // Step 3 -- Output result of calculations. System.out.printf ("The sum of %d and %d is %d\n", first, second, sum); } } /* Example I/O when we run the program: * Please enter first number: 17 * Please enter second number: 3 * The sum is of 17 and 3 is 20 */