-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverage.java
More file actions
30 lines (24 loc) · 771 Bytes
/
Average.java
File metadata and controls
30 lines (24 loc) · 771 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
class AverageSub {
private int[] data;
private int sum = 0;
public AverageSub(int[] init) {
data = new int[init.length];
for (int j = 0 ; j < data.length ; j++)
data[j] = init[j];
}
public int average() {
for (int a = 0 ; a < data.length ; a++)
sum += data[a];
return sum / data.length;
}
}
public class Average {
public static void main(String[] args) {
int[] values = { 98, 99, 98, 99, 100, 101, 102, 100, 104, 105,
105, 106, 105, 103, 104, 103, 105, 106, 107, 106,
105, 105, 104, 104, 103, 102, 102, 101, 100, 102};
AverageSub june = new AverageSub(values);
int avg = june.average();
System.out.println("Average = " + avg);
}
}