Add.java


This is the syntax highlighted version of Add.java from 2.4 Input and Output of
Introduction to Computer Science by Robert Sedgewick and Kevin Wayne.


/*************************************************************************
 *  Compilation:  javac Add.java
 *  Execution:    java Add
 *  Dependencies: StdIn.java
 *  
 *  Prompts the user for two integers numbers, reads them in from standard
 *  input, and prints out their sum.
 *
 *  Note: you must hav the file StdIn.java in your working directory.
 *
 *  % java Add
 *  Type the first integer
 *  5                                 <--  user types this
 *  Type the second integer
 *  33                                <--  user types this
 *  Their sum is 38
 *
 *************************************************************************/

public class Add { 
    public static void main(String[] args) { 
        System.out.println("Type the first integer");
        int x = StdIn.readInt();

        System.out.println("Type the second integer");
        int y = StdIn.readInt();

        int z = x + y;
        System.out.println("Their sum is " + z);
   }
}


Last updated: Mon Jul 26 16:33:49 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.