程序结构:
①顺序结构
②分支结构 if ?= switch
③循环结构 do—while for
跳转语句 break continue
数组:
①数组声明
int[] nums;
double scores[];
②分配空间(new)
nums = new int[5];
③改变数组长度
int[] nums = new int[5];
nums = new int[3]; //nums长度由5变成3
④赋值
nums[0] = 12;
也可以将声明、分配空间、赋值放在一起,如下
int[] nums = {12,15,55,77};
String[] names = new String[]{“Hello”,”world”,”Jack”,”Jenny”};
数组间也可以赋值,如下
nums1 = nums; //nums1和nums将指向同一组空间,且nums1的长度等于nums.length
//nums1和nums类型必须一样,不然会出错
⑤访问数组元素
int a = nums[2];
⑥获取数组长度
int count = nums.length; //数组下标从0到count