-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSumFun.java
More file actions
25 lines (19 loc) · 724 Bytes
/
Copy pathSumFun.java
File metadata and controls
25 lines (19 loc) · 724 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
import java.util.Scanner;
public class SumFun {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int sum = 0;
int input;
//priming read
System.out.println("Enter non-negative to add to sum");
System.out.println("Enter a negative to exit!");
input = keyboard.nextInt();
while(input >= 0) {
sum += input; //sum = sum + input;
System.out.println("Enter non-negative to add to sum");
System.out.println("Enter a negative to exit!");
input = keyboard.nextInt();
}//end while
System.out.println("Sum is " + sum);
}//end main
}