Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fig. 2.7: Addition.java
- // Addition program that inputs two numbers then displays their sum.
- import java.util.Scanner; // program uses class Scanner
- public class Addition
- {
- // 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);
- int number1 = 0; // first number to add
- int number2 = 0; // second number to add
- int sum = 0; // sum of number1 and number2
- System.out.print("Enter first integer: "); // prompt
- number1 = input.nextInt(); // read first number from user *** hangs! ***
- System.out.print("Enter second integer: "); // prompt
- number2 = input.nextInt(); // read second number from user *** hangs! ***
- sum = number1 + number2; // add numbers, then store total in sum
- System.out.printf("Sum is %d%n", sum); // display sum
- } // end method main
- } // end class Addition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement