zoukankan      html  css  js  c++  java
  • 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);
        }
        
    }
  • 相关阅读:
    抽象类和接口
    truncate,delete和drop的区别
    PLSQL乱码问题
    Linux
    myEclipse闪退
    Java 中 Synchronized 的使用
    工厂模式
    Java中的File,IO流
    jQuery的学习
    C++中的标准模板库STL
  • 原文地址:https://www.cnblogs.com/lxh520/p/8313678.html
Copyright © 2011-2022 走看看