您的位置:首页 > 其它

数组的2种初始化方式

2017-06-28 00:00 316 查看
public class AgeDemo {
public static void main(String[] args) {
int[] age = {0, 3, 2, 23};
System.out.println(age[2]);
System.out.println(age.length);
for(int x = 0; x < age.length; x++) {
System.out.println(age[x]);
}

}
}

D:\subline\lesson011>java AgeDemo
2
4
0
3
2
23

D:\subline\lesson011>

第二种

public class AgeDemo {
public static void main(String[] args) {
int[] age = new int[4];
System.out.println(age[2]);
System.out.println(age.length);
for(int x = 0; x < age.length; x++) {
System.out.println(age[x]);
}

}
}

D:\subline\lesson011>java AgeDemo
0
4
0
0
0
0

D:\subline\lesson011>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: