1. 声明数组
1. 数据类型[] 数组名
int[] scores;
string[] names;
2. 数据类型 数组名[]
double height[];
2. 分配空间
就是指定数组中最多可以存储多少个元素
语法:数组名 = new 数组类型[数组长度]
scores = new int[5];
height = new double[5];
声明数组的同时分配空间
int[] scores = new int[5];
3. 赋值
scores[0] = 100;
4. 处理数组中的成绩
System.out.println("scores数组中第一个元素的值:" + scores[0])
int[] scores = {1,2,3,4,5} 创建一个长度为4的整型数组
等价于
int[] scores = new int[]{1,2,3,4,5}
第二种int后面的[]里面不能指定长度
5. 使用循环操作Java中数组
数组名.length用于获取数组的长度