配列
public class Main {
public static void main(String[] args) {
// ① 配列の準備: 5人分の点数を最初から格納
int[] scores = {80, 75, 90, 65, 100};
// ② 合計点を入れる箱(変数)を0で初期化
int total = 0;
// ③ for文で、配列の全要素を順番に処理する
// scores.length は「配列の長さ(この場合 5)」を意味します
for (int i = 0; i < scores.length; i++) {
// i番目の点数を total に足していく(total = total + scores[i] と同じ)
total = total + scores[i];
// 処理がわかりやすいように、 i と点数を出力してみる
System.out.println((i + 1) + "番目の点数は: " + scores[i]);
}
// ④ 合計点と平均点を計算・表示
int average = total / scores.length;
System.out.println("--------------------");
System.out.println("合計点: " + total);
System.out.println("平均点: " + average);
}
}
☆とても長いけど、点数一覧と平均値が出てくるからとても便利!
たくさん打てば覚えるらしい(自分もハローワールドもまだ完璧ではない笑)




