6-4 静态内部类

package innerclass;

public class InnerClassThree {

    int x;
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        double[] value = new double[20];
        for (int i = 0; i < 20; i++) {
            value[i] = 100*Math.random();
        }
        ArrayAlg.Pair pair = ArrayAlg.getMaxMin(value);
        System.out.println(pair.getFirst());
        System.out.println(pair.getSecond());
    }
    
    /**
     * 静态内部类,内部类不能引用外部类的对象
     * 
     * 只能有静态域和静态方法
     */
    
     static class innerClass{
//        int y = x;
    }
}


class ArrayAlg{
    
    public static class Pair{
        
        private double first;
        private double second;
        
        public Pair(double f,double s){
            first = f;
            second  = s;
        }
        public double getFirst(){
            return first;
        }
        
        public double getSecond(){
            return second;
        }
    } 
    
    
    public static Pair getMaxMin(double[] value){
        double max = Double.POSITIVE_INFINITY;
        double min = Double.NEGATIVE_INFINITY;
        for (double d : value) {
            if (max<d) {
                max = d;
            }
            if (min>d){
                min = d;
            }
        }
        return new Pair(max, min);
    }
    
}

 

posted @ 2018-01-19 00:13  aLa神灯  阅读(84)  评论(0编辑  收藏  举报