- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentinelLoop.java
More file actions
Latest commit
31 lines (25 loc) · 641 Bytes
/
Copy pathSentinelLoop.java
File metadata and controls
31 lines (25 loc) · 641 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
importjava.util.Scanner;
publicclassSentinelLoop{
publicstaticvoidmain(String[] args) {
Scannerinput = newScanner(System.in);
intsum = 0;
doubleaverage;
longproduct = 1;
intcounter = 0;
System.out.println("Enter -1 to amrk end of input");
while(true) {
System.out.print("Enter number: ");
intnum = input.nextInt();
if(num == -1 ) {
break;
}
counter ++;
sum += num;
product *= num;
}
average = (double)sum/counter;
System.out.printf("The sum is %d%n",sum);
System.out.printf("The average is %2.f%n",average);
System.out.printf("The product is %d%n",product);
}
}