public class Demo03 { public static void main(String[] args) { Demo03 demo03 = new Demo03(); demo03.test(1);//输出1 } public void test(int... i){ System.out.println(i[0]); } }
public class Demo03 { public static void main(String[] args) { Demo03 demo03 = new Demo03(); demo03.test(1,2,3,4,5);//输出1 } public void test(int... i){ System.out.println(i[0]);//1 System.out.println(i[1]);//2 System.out.println(i[2]);//3 System.out.println(i[3]);//4 System.out.println(i[4]);//5 } }
public class Demo04 { public static void main(String[] args) { //调用可变参数的方法 printMax(34,3,3,2,56.5);//The max value is34.0 printMax(new double[]{1,2,3});//The max value is3.0 } 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.length > result){ result = numbers[i]; } } System.out.println("The max value is"+result); }
标签:Java,05,void,System,numbers,可变,println,public,out From: https://www.cnblogs.com/sankouyitouju/p/17836342.html