package average import java io PrintWriter public class Average public

 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
package average;
import java.io.PrintWriter;
public class Average {
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out, true);
pw.println("Пример работы с обобщениями\nby vovka.pw\n");
Double[] doubleNumbers = {
5_124.8,
7_897_500.5,
5.7,
900.865_991,
9.5E3
};
Integer[] intNumbers = {
100_000,
500_000,
624,
150_111_671
};
AverageClass<Double> da = new AverageClass<Double>(doubleNumbers);
AverageClass<Integer> ia = new AverageClass<Integer>(intNumbers);
pw.println("Double Array average = " + da.getAverage()); //Double Array average = 1582606.3731982
pw.println("Integer Array average = " + ia.getAverage()); //Integer Array average = 3.767807375E7
pw.println("Double Array average " + (da.sameAverage(ia) ? ">=" : "<") + " Integer Array average"); //Double Array average < Integer Array average
}
}