我有一个数组
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2,
13.9 });
values.add(new double[] { 10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14, 11 });
values.add(new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6 });
values.add(new double[] { 9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 });
如何找到最大值和最小值?
答案 0 :(得分:5)
尝试
double min=Double.MAX_VALUE, max=Double.MIN_VALUE;
for (double[] ds : values) {
for (double d : ds) {
if (d > max) max=d;
if (d < min ) min=d;
}
}
答案 1 :(得分:1)
这种方法也很有用:
public double getMaxValue(List<Double> values){
double maxValue = Double.MIN_VALUE;
for(Double d : values){
if(d > maxValue){
d = maxValue
}
}
}