// A Java program to read two numbers, add them, and print their sum.
//                          R. G. Larson 12/31/98, H. Burgiel 1/20/99

import java.io.*;       // Give the location and load the packages for
                        // reading input and writing output.

public class AddNums  { // Name the program we are writing

  // All Java programs have a "main" method which is the first thing
  // run when the program is executed.  This is similar to the "init"
  // method of an applet.  Because the method we are using to read
  // input might generate (throw) an IOException error, we have to
  // either give explicit instructions for handling such an error in
  // this method, or declare that the method might pass such an error
  // on to the program calling it.

  public static void main(String[] args) throws IOException {

    // This makes a note of what variables we will use in this method.
    // We also record here what each one is used for.  This is very
    // useful information to have handy when debugging a program or
    // when reading someone else's program for the first time.

    int i, j, sum;        // Two integers and their sum.
    BufferedReader in;    // Input stream from which we read integers.

    // To read data from standard input we create a new object of type
    // BufferedReader and assign it the variable name "in".
    // "System.in" is the standard input stream object which carries
    // information from the keyboard or a file to the program.

    in = new BufferedReader( new InputStreamReader(System.in));

    // "System.out" is an output stream object which carries
    // information from the computer to a screen, file or printer.  We
    // use the println method of this object to write instructions to
    // the screen.

    System.out.println("A java program to add two integers.");
    System.out.println("Enter the first integer:  ");
    
    // Here we convert some data read by the readLine method of
    // BufferedReader "in" into an integer, which we call A.

    i = Integer.parseInt( in.readLine().trim() );

    // We repeat the process of writing instructions to the screen and
    // receiving a response from the keyboard.

    System.out.println("Enter the second integer:  ");
    j = Integer.parseInt( in.readLine().trim() );

    // Add the two numbers we just read,
    sum = i + j;

    // and output their sum.
    System.out.println("The sum of " + i + " and " + j + " is " + sum + ".");

  } // End method main
} // End class AddNums
