回答編集履歴

1

ソース追記

2019/09/30 04:27

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -69,3 +69,107 @@
69
69
  ```
70
70
 
71
71
  と、なりますが・・・
72
+
73
+
74
+
75
+ 「追記」ぜったい“これが正解"とは言えないのですが・・・
76
+
77
+ ```java
78
+
79
+ /*
80
+
81
+ * Copyright © 2019 CatEye <cateye@sirius.ocn.ne.jp>
82
+
83
+ */
84
+
85
+ package javatest1;
86
+
87
+
88
+
89
+ /**
90
+
91
+ *
92
+
93
+ * @author CatEye <cateye@sirius.ocn.ne.jp>
94
+
95
+ */
96
+
97
+ public class Javatest1 {
98
+
99
+
100
+
101
+ /**
102
+
103
+ * @param args the command line arguments
104
+
105
+ */
106
+
107
+ public static void main(String[] args) {
108
+
109
+
110
+
111
+ int[][] IntArray = {
112
+
113
+ {30, 24, 24}, //1年:1組,2組,3組
114
+
115
+ {29, 21, 26}, //2年:1組,2組,3組
116
+
117
+ {31, 31, 31}, //3年:1組,2組,3組
118
+
119
+ };
120
+
121
+
122
+
123
+ intArray(IntArray);
124
+
125
+ }
126
+
127
+
128
+
129
+ public static void intArray(int[][] a) {
130
+
131
+ System.out.println("各学年の合計人数は、");
132
+
133
+ for (int i = 0; i < a.length; i++) {
134
+
135
+ int sum = 0;
136
+
137
+ for (int j = 0; j < a[i].length; j++) {
138
+
139
+ sum += a[i][j];
140
+
141
+ }
142
+
143
+ System.out.println(i + 1 + "年:" + sum + "人");
144
+
145
+ }
146
+
147
+ System.out.println("です。");
148
+
149
+ }
150
+
151
+
152
+
153
+ }
154
+
155
+ ```
156
+
157
+ 結果
158
+
159
+ ```text
160
+
161
+ run:
162
+
163
+ 各学年の合計人数は、
164
+
165
+ 1年:78人
166
+
167
+ 2年:76人
168
+
169
+ 3年:93人
170
+
171
+ です。
172
+
173
+ BUILD SUCCESSFUL (total time: 0 seconds)
174
+
175
+ ```