質問編集履歴

3

追記

2020/04/04 06:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -168,6 +168,8 @@
168
168
 
169
169
  となってしまいました
170
170
 
171
+ 追記sum_kokugo sum_mathが数値型ではなかったため起きたエラーでした
172
+
171
173
  ```Ruby
172
174
 
173
175
  class PointTotalization
@@ -203,3 +205,45 @@
203
205
  end
204
206
 
205
207
  ```
208
+
209
+
210
+
211
+ こうしたらちゃんと動きました
212
+
213
+
214
+
215
+ ```Ruby
216
+
217
+ class PointTotalization
218
+
219
+ puts "6人の国語・数学の点数を入力せよ"
220
+
221
+ i = 0
222
+
223
+ sum_kokugo = 0
224
+
225
+ sum_math = 0
226
+
227
+ while i < 6
228
+
229
+ print "#{i+1}番...国語:"
230
+
231
+ kokugo = gets.to_i
232
+
233
+ print " 数学:"
234
+
235
+ math = gets.to_i
236
+
237
+ sum_kokugo += kokugo
238
+
239
+ sum_math += math
240
+
241
+ i += 1
242
+
243
+ end
244
+
245
+ puts "平均 #{sum_kokugo/6} #{sum_math/6}"
246
+
247
+ end
248
+
249
+ ```

2

追記

2020/04/04 06:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -159,3 +159,47 @@
159
159
 
160
160
 
161
161
  ```
162
+
163
+
164
+
165
+ とりあえず平均だけだそうと思ったのですが、
166
+
167
+ <class:PointTotalization>': undefined method `+' for nil:NilClass (NoMethodError)
168
+
169
+ となってしまいました
170
+
171
+ ```Ruby
172
+
173
+ class PointTotalization
174
+
175
+ puts "6人の国語・数学の点数を入力せよ"
176
+
177
+ #point = Array.new(2)
178
+
179
+ #kokugo = point[0]
180
+
181
+ #math = point[1]
182
+
183
+ i = 0
184
+
185
+ while i < 7
186
+
187
+ print "#{i+1}番...国語:"
188
+
189
+ kokugo = gets.to_i
190
+
191
+ print " 数学:"
192
+
193
+ math = gets.to_i
194
+
195
+ sum_kokugo += kokugo
196
+
197
+ sum_math += math
198
+
199
+ end
200
+
201
+ puts "平均 #{sum_kokugo/6} #{sum_math/6}"
202
+
203
+ end
204
+
205
+ ```

1

改善

2020/04/04 06:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,92 @@
5
5
  どう書いたらいいのかわかりません
6
6
 
7
7
  教えてくれるとありがたいです
8
+
9
+
10
+
11
+
12
+
13
+ 下がjavaの元のコードです
14
+
15
+
16
+
17
+ ```Java
18
+
19
+ import java.util.Scanner
20
+
21
+
22
+
23
+ class PointTotalization {
24
+
25
+
26
+
27
+ public static void main (String[] args) {
28
+
29
+ Scanner stdIn = new Scanner(System.in);
30
+
31
+ final int NINZU = 6;
32
+
33
+ int[][] point = new int[NINZU][2];
34
+
35
+ int[] sumStudent = new int[NINZU];
36
+
37
+ int[] sumSubject = new int[2];
38
+
39
+
40
+
41
+ System.out.printf("%d人の国語・数学の点数を入力せよ。\n", NINZU);
42
+
43
+
44
+
45
+ for (int i = 0; i < NINZU; i++) {
46
+
47
+ System.out.printf("%2d番...国語:", i + 1);
48
+
49
+ point[i][0] = stdIn.nextInt();
50
+
51
+ System.out.print(" 数学":);
52
+
53
+ point[i][1] = stdIn.nextInt();
54
+
55
+
56
+
57
+ sumStudent[i] = point[i][0] + point[i][1];
58
+
59
+ sumSubject[0] += point[i][0];
60
+
61
+ sumSubject[1] += point[i][1];
62
+
63
+ }
64
+
65
+
66
+
67
+ System.out.println("No. 国語 数学 平均");
68
+
69
+ for (int i = 0; i < NINZU; i++)
70
+
71
+ System.out.printf("%2d%6d%6d%6.1f\n", i + 1, point[i][0], point[i][1],(double)sumStudent[i] / 2);
72
+
73
+ System.out.printf("平均%6.1f%6.1f\n", (double)sumSubject[0] / NINZU, (double)sumSubject[1] / NINZU)
74
+
75
+ }
76
+
77
+ }
78
+
79
+ ```
80
+
81
+
82
+
83
+ これが僕が書いたRubyのコードです
84
+
85
+
86
+
87
+ エラーは文はこちらです
88
+
89
+ `<class:PointTotalization>': undefined method `+' for nil:NilClass (NoMethodError)
90
+
91
+
92
+
93
+
8
94
 
9
95
 
10
96