代码如下:
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);
}
时间: 2024-10-11 16:57:37