使用数组,数组使用下标来操控数组中的数居
数组名[0]=78;
数组名[1]=80;
数组的下标是从0开始的,最大的下标为“数组大小-1”
例外:声明加赋值- int[] grades={78,80,90};//注意,该数组现在容量为3
复制代码 例如- String[] ss={
- "张三","李四","王五"
- };
- System.out.println(ss[1]);
复制代码 4,数组的遍历- String[] ss={
- "张三","李四","王五","赵六","陈七","刘八"
- };
- for(int i=0;i<6;i++){
- System.out.println(ss[i]);
- }
复制代码 数组的一个属性length- String[] ss={
- "张三","李四","王五","赵六","陈七","刘八","久久"
- };
- for(int i=0;i<ss.length;i++){
- System.out.println(ss[i]);
- }
复制代码 |