更にサンプル
public class sample1 {
public static void main(String[] args) throws Exception {
int[] i = new int[10];
//for文を使ってデータを挿入
for (int j = 0; j < 10; j++) {
i[j] = j * 2;
}
int total = 0;
//for文を使って配列に入っている値の和を求めます
for (int j = 0; j < 10; j++) {
total = total + i[j];
}
for (int j = 0; j < 10; j++) {
System.out.print("i[");
System.out.print(j);
System.out.print("]=");
System.out.println(i[j]);
}
//最後に結果を表示します
System.out.print("合計=");
System.out.println(total);
}
}