/* This program "Adder" will ask the user to enter 2 numbers, and then * print their sum. This is a relatively simple program, requiring only one * class (file). Within the main() function we see the 3 classic parts to * a typical program: input, calculations, output. */ import java.io.*; // include I/O library so we can do input public class Adder2 { public static void main(String [] args) throws IOException { // Step 1 -- Get input. Ask user to enter 2 numbers, and read them in. // tell computer we want to use keyboard input BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in)); System.out.println ("Welcome to the Adder program. You give me two"); System.out.println ("numbers, and I will tell you their sum."); System.out.print ("Please enter first number: "); int first = Integer.parseInt(kbd.readLine()); System.out.print ("Please enter second number: "); int second = Integer.parseInt(kbd.readLine()); // Step 2 -- Perform calculations. int sum = first + second; // Step 3 -- Output result of calculations. System.out.println ("The sum is " + sum); } } /* Example I/O when we run the program: * Please enter first number: 14 * Please enter second number: -8 * The sum is 6 */