静态内部类

package com.sadhu;
import java.util.*;
/**
静态内部类
只有静态内部类才能用static关键字修饰。
静态内部类可以单独实例化,不需要外部类的引用对象
*/
public class Sample
{
    public static void main(String[] args)throws Exception
    {
        double[] d = new double[20];
        for(int i = 0;i < d.length;i++)
        {
            d[i] = 100*Math.random();
        }
        ArrayAlg.Pair p = ArrayAlg.minMax(d);
        System.out.println("min= " + p.getFirst());
        System.out.println("max= " + p.getSecond());
    }
}
class ArrayAlg
{
    public static class Pair
    {
        public Pair(double f,double s)
        {
            first = f;
            second = s;
        }
        public double getFirst()
        {
            return first;
        }
        public double getSecond()
        {
            return second;
        }
        private double first;
        private double second;
    }
    public static Pair minMax(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);
    }
}


你可能感兴趣的:(静态内部类)