package s0221可变参数; |
public class Main { |
public static void main(String [] args){ |
|
printToConsolo( "张三" , "李四" ); |
System.out.println(); |
printToConsolo( 10 , "张三" , "李四" ); |
} |
|
public static void printToConsolo(String... x) // String...x 表示可以输入数量不限,类型相同的参数 |
{ |
for (String temp : x) { |
if (temp != null ) { |
System.out.println( "第一次你输入的是---" +temp);; |
} |
} |
} |
public static void printToConsolo( int age,String... x) // 可变参数只能有一个,而且只能放到所有参数的最后面 |
{ |
System.out.println( "第二次你输入的是---" +age); |
for (String temp : x) { |
if (temp != null ) { |
System.out.println( "第二次你输入的是---" +temp);; |
} |
} |
} |
} |