配列作業手順
int[] scores; //①
scores = new int[5]; //②
[5] = 0,1,2,3,4 中身ゼロから数えて[5]
①と②同時に行う
int[] scores = new int[5]; //①②
配列作成省略記法
int[] scores1 = new int[] {10, 20, 30, 40, 50};
int[] scores2 = {10, 20, 30, 40, 50};
上下同じ意味
forループで配列を回す
int[] scores = {10, 20, 30, 40, 50};
for (int i = 0; i < scores.length; i++) {
System.out.println(scores[i]);
ループ変数名は任意で指定可能
拡張 for 文で配列を回す
int[] scores = {10, 20, 30, 40, 50};
for (int value : scores) {
System.out.println(value);
上のfor文であったループ変数や配列の添字を記述する必要がなくなる
length使用方法
配列のlength
文字列のlength()