-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE12pro.java
35 lines (26 loc) · 990 Bytes
/
E12pro.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
27
28
29
30
31
32
33
34
35
/*
* Original: Write a Java program that takes three numbers as input to calculate and print the average of the numbers.
*
* Mine (pro): Write a Java program that takes an unknown amount of numbers as input to calculate and print their average.
*/
package w3resourceExcersises;
import java.util.Scanner;
public class E12pro {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Start inputing numbers to calculate their average. Input 0 to terminate the input stream and get the output.");
double numX = sc.nextDouble();
double sum = numX;
int i = 0;
while (numX != 0) {
System.out.println("Insert next number...");
numX = sc.nextDouble();
sum = sum + numX;
i++;
};
double avg = (sum / i);
System.out.println("The average of the inputed numbers( which were " + i + " in total ) is: " + avg +" .");
sc.close();
}
}