可变参数

可变参数

public class Demo02 {
    public static void main(String[] args) {
            Demo02 demo02 = new Demo02();
            demo02.test(1,5,5,5,5,5,5,5,5);
        System.out.println("===============");
        demo02.printMax(12,3,5,8);
        demo02.printMax(new double[]{1,2,3,47,9});

    }
    public void test(int... i){
        System.out.println(i[5]);
    }
    public static void printMax(double...numbers){
        if(numbers.length == 0){
            System.out.println("傻瓜");
            return;
        }
        double result = numbers[0];
        for (int i = 1; i<numbers.length ; i++){
            if (numbers[i] > result){
                System.out.println(numbers[i]);
                result = numbers[i];
            }
        }
        System.out.println("最大的是"+ result);
    }
}

可变参数

上一篇:Demo02


下一篇:Helloworld