package timer;
/**
* 静态内部类
*/
public class StaticInnerClass {
public static void main(String[] args) {
double[] d = new double[20];
for(int i=0; i<d.length; i++) {
d[i] = 100 * Math.random();
}
ArrayAlg.Pair p = ArrayAlg.min_max(d);
System.out.println("min = " + p.getFirst());
System.out.println("max = " + p.getSecond());
}
}
class ArrayAlg {
/**
* 返回数组中的最大值和最小值
*/
public static Pair min_max(double... values) {
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
for(double v : values) {
if(min > v) {
min = v;
}
if(max < v) {
max = v;
}
}
return new Pair(min, max);
}
public static class Pair {
private double first;
private double second;
public Pair(double first, double second) {
this.first = first;
this.second = second;
}
public double getFirst() {
return first;
}
public double getSecond() {
return second;
}
}
}