第一次写博客记录学习java遇到的问题,学习java学到方法的时候,在想见过c语言有类似多个参数传递的写法,java也应该有类似的写法,通过学习掌握的这种写法,如下
public class Test {public static void print(String ... str){// str 作为一个可变化参数数量的字符串数组传递for(String x:str){ //简便方式循环遍历数组System.out.println(x);}}public static void main(String args[]) {print("hello word");print("哈哈哈","1","ff","猜猜我是谁");}
}
运行结果