JAVA问题总结之20--可变长度形参

JAVA问题总结之20--可变长度形参

package JAVA830;

public class test1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestHello s1=new TestHello();
		s1.SayHello();
		String ss1="xubo";
		s1.SayHello(ss1);
		System.out.print("\n");
		s1.SayHello(new String[]{"ustc","sz","502"});

	}
}
class TestHello{
	public void SayHello(){
		System.out.println("hello world");
		}
	public void SayHello(String str1){
		System.out.println("hello\t"+str1);
		}
//	public void SayHello(String[] str2){
//		
//		System.out.println("hello\t"+str2.length);
//		for (int i=0;i<str2.length;i++){
//			System.out.println(str2[i]);
//		}
//		}
    public void SayHello(String ... str3){
		
		System.out.println("hello\t"+str3.length);
		for (int i=0;i<str3.length;i++){
			System.out.println(str3[i]+"$");
		}
		}
}

输出:

hello world
hello	xubo

hello	3
ustc$
sz$
502$




你可能感兴趣的:(java)