public class Demo04 {标签:调用,double,printMax,public,参数,numbers,可变,method,result From: https://www.cnblogs.com/123jgh/p/16784993.html
//在方法声明中,在指定参数类型后加一个省略号...
//一个方法只能指定一个可变参数,它必须是方法的最后一个参数,任何普通的参数必须在它之前声明
public static void main(String[] args) {
//调用可变参数的方法
printMax(34,4,35,55,90.8,78.9);
printMax(new double[]{1,2,8,4,5,6});
}
public static void printMax(double... numbers){
if (numbers.length == 0){
System.out.println("no argument passed");
return;
}
double result = numbers[0];
//排序
for (int i = 1;i < numbers.length;i++){
if (numbers[i] > result){
result = numbers[i];
}
}
System.out.println("the max value is "+result);
}
}