可变参数
public class Demo04 {
public static void main(String[] args) {
test(1,2,3,4,5,6);
}
//方法中包含可变参数
public static void test(int... i){
System.out.println(i[4]);
System.out.println(i[1]);
System.out.println(i[2]);
System.out.println(i[3]);
}
}
比大小
public class Demo05 {
public static void main(String[] args) {
printMax(1,2,3,4,5); //两种调用方法
printMax(new double[]{1,2,3,4,5,6}); //调用方法
}
//可变参数比大小
public static void printMax(double... num){
if(num.length == 0){
System.out.println("NO");
return;
}
double result = num[0];
for (int i = 1;i<num.length;i++){
if(num[i]>result){
result = num[i];
}
}
System.out.println(result);
}
}
标签:19,System,num,参数,可变,println,static,public,out
From: https://www.cnblogs.com/PedroPascal/p/17095084.html