可变参数

public class HelloWorld {
    public static void main(String[] args) {

        printMax(321,4564,879,645,2,7,75,31,7453,46);

    }
    public static void printMax(double... numbers){
        if (numbers.length==0){
            System.out.println("no argument");
            return;
        }
        double result = 0;
        for(int i=1;i<numbers.length;i++){
            if (numbers[i]>result){
                result = numbers[i];
            }
        }
        System.out.println("the max data is" + result);
    }
上一篇:基本算法总结篇


下一篇:不修改数组找出重复的数字