数组作为参数传递
class A{
void p(int[] a){
int i;
for(i=0;i<6;i++){
System.out.println(a[i]);
}
}
void q(String[] b){
int i;
for(i=0;i<3;i++){
System.out.println(b[i]);
}
}
void g(char[] c){
int i;
for(i=0;i<3;i++){
System.out.println(c[i]);
}
}
}
public class try02 {
public static void main(String arg[]){
int[] list = {1,2,3,4,5,6};//定义数组Int字符串字符类型
String[] list1={"123","456","789"};
char[] list2={'a','b','c'};
A a = new A();
//a.p(new int[]{1,2,3,4,5,6});第二种方法在传递中初始化数组
a.p(list);
a.q(list1);
a.g(list2);
}
}
结果:
1
2
3
4
5
6
123
456
789
a
b
c
静,静,静