可变长参数列表
代码如下:
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);
}
只相信苦尽甘来