其他分享
首页 > 其他分享> > 可变参数

可变参数

作者:互联网

image

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);
    }
}

image

标签:System,demo02,参数,numbers,可变,println,public,out
来源: https://www.cnblogs.com/wcwjava/p/15251038.html