-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvgNums.java
More file actions
36 lines (32 loc) · 1.05 KB
/
AvgNums.java
File metadata and controls
36 lines (32 loc) · 1.05 KB
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
import java.io.*;
class AvgNums {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
double sum = 0.0;
double avg, t;
System.out.println("How much numbers you will put down: ");
str = br.readLine();
try {
n = Integer.parseInt(str);
} catch(NumberFormatException exc) {
System.out.println("Incorrect format");
n = 0;
}
System.out.println("Entering " + n + " numbers");
for(int i = 0; i < n; i++) {
System.out.print(": ");
str = br.readLine();
try {
t = Double.parseDouble(str);
} catch(NumberFormatException exc) {
System.out.println("Incorrect format");
t = 0.0;
}
sum += t;
}
avg = sum / n;
System.out.println("Average is: " + avg + ". Sum is:" + sum);
}
}