public class Test {
public void test(String... body){
//String...代表String的数组,长度由传进来时的数组长度决定
for (int i = 0; i < body.length; i++) {
System.out.print(body[i]);
}
System.out.println();
}
}
public class Main {
public static void main(String[] args) {
Test t=new Test();
t.test("hello,","hi");
t.test("good morning");
t.test("good afternoon,","good evening,","good night");
}
}
输出结果:
hello,hi
good morning
good afternoon,good evening,good night
转自:www.blogjava.net/hanbihui/archive/2007/09/19/146428.html