可变长参数列表

代码如下:


public class VarArgumentsDemo {
public static void main(String[] args) {
printMax();
} private static void printMax(double... numbers) {
// TODO Auto-generated method stub
if (numbers.length == 0) {
System.out.println("No args");
return;
}
double result = numbers[0];
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > result) {
result = numbers[i];
}
}
System.out.println("Max value is " + result);
}

posted @ 2017-06-20 18:25  辰峰  阅读(221)  评论(0编辑  收藏  举报