Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // Fig. 2.7: Addition.java
  2. // Addition program that inputs two numbers then displays their sum.
  3. import java.util.Scanner; // program uses class Scanner
  4.  
  5. public class Addition
  6. {
  7. // main method begins execution of Java application
  8. public static void main(String[] args)
  9. {
  10. // create a Scanner to obtain input from the command window
  11. Scanner input = new Scanner(System.in);
  12.  
  13. int number1 = 0; // first number to add
  14. int number2 = 0; // second number to add
  15. int sum = 0; // sum of number1 and number2
  16.  
  17. System.out.print("Enter first integer: "); // prompt
  18. number1 = input.nextInt(); // read first number from user *** hangs! ***
  19.  
  20. System.out.print("Enter second integer: "); // prompt
  21. number2 = input.nextInt(); // read second number from user *** hangs! ***
  22.  
  23. sum = number1 + number2; // add numbers, then store total in sum
  24.  
  25. System.out.printf("Sum is %d%n", sum); // display sum
  26. } // end method main
  27. } // end class Addition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement