- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop.java
More file actions
Latest commit
27 lines (20 loc) · 494 Bytes
/
Copy pathLoop.java
File metadata and controls
27 lines (20 loc) · 494 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
importjava.util.Scanner;
publicclassLoop {
publicstaticvoidmain(String[] args) {
intsum = 0;
intcount = 0;
intnumber;
Scannerscanner = newScanner(System.in);
while (true) {
System.out.print("Enter a number (-1 to quit): ");
number = scanner.nextInt();
if (number == -1) {
break;
}
sum += number;
count++;
}
System.out.println("Sum of " + count + " numbers is: " + sum);
scanner.close();
}
}