-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathAddNumbers.java
More file actions
37 lines (25 loc) · 900 Bytes
/
AddNumbers.java
File metadata and controls
37 lines (25 loc) · 900 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
package chapter4;
import java.util.Scanner;
/*
* DO WHILE LOOP:
* Write a program that allows a user to enter two numbers,
* and then sums up the two numbers. The user should be able to
* repeat this action until they indicate they are done.
*/
public class AddNumbers {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
boolean again;
do{
System.out.println("Enter the first number");
double num1 = scanner.nextDouble();
System.out.println("Enter the second number");
double num2 = scanner.nextDouble();
double sum = num1 + num2;
System.out.println("The sum is " + sum);
System.out.println("Would you like to start over? True or False");
again = scanner.nextBoolean();
} while(again);
scanner.close();
}
}