可变参数
package ff;
public class Dome4 {
public static void main(String[] args) {
Dome4 dome4 = new Dome4();
dome4.test(1);
}
public void test(int...i){
System.out.println(i[0]);
}
}
package ff;
public class Dome5 {
public static void main(String[] args) {
printMax(34,3,3,2,56,5);
printMax(new double[]{1,2,3});
}
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);
}
}