-
Notifications
You must be signed in to change notification settings - Fork 0
/
Addition.java
26 lines (20 loc) · 967 Bytes
/
Addition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Addition.java
// Addition program that display the sum of two numbers.
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 windows
Scanner input = new Scanner( System.in );
int number1; // first number to add
int number2; // second number to add
int sum; // sum of number1 and number2
System.out.print( "Enter first integer: "); // prompt
number1 = input.nextInt(); // read first number from user
System.out.print( "Enter second integer: "); // prompt
number2 = input.nextInt(); // read second number from user
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