質問編集履歴

2

エラー内容併記

2019/01/19 08:58

投稿

Yuta25jp
Yuta25jp

スコア13

test CHANGED
@@ -1 +1 @@
1
- Javaで間違い回答番号を出力したいです。
1
+ Javaで間違い回答番号を出力したいです。[配列処理に困っている]
test CHANGED
@@ -124,7 +124,7 @@
124
124
 
125
125
  int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
126
126
 
127
- int correct=0,error=0,total=10;
127
+ int correct=0,error=0,errornum,total=10;
128
128
 
129
129
 
130
130
 
@@ -140,6 +140,8 @@
140
140
 
141
141
  if (ans==V[i])correct++; // 正解の場合
142
142
 
143
+ else if (ans!=V[i]) errornum = V[i];
144
+
143
145
  else error++; // 不正解の場合
144
146
 
145
147
  System.out.println();
@@ -154,7 +156,7 @@
154
156
 
155
157
  System.out.println("正答率は"+ percent + "%でした.");
156
158
 
157
-
159
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
158
160
 
159
161
 
160
162
 
@@ -164,31 +166,83 @@
164
166
 
165
167
 
166
168
 
169
+
170
+
171
+ ```
172
+
173
+ ### 試したこと
174
+
175
+
176
+
177
+ 間違った問題の配列番号を読み取って、その問題番号を出力するために
178
+
179
+
180
+
181
+ ```
182
+
183
+ else if (ans!=V[i]) errornum = V[i] //for文の中に記入
184
+
185
+ System.out.println("不正解番号は"+ V[i} + "番でした."); //全体の最後
186
+
187
+ ```
188
+
189
+ を記入しているのですが、コンパイルに失敗してしまい、下記のエラーが表示されました。
190
+
191
+
192
+
193
+ ```
194
+
195
+ Eitango.java:67: エラー: ']'がありません
196
+
197
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
198
+
199
+ ^
200
+
201
+ Eitango.java:67: エラー: 文ではありません
202
+
203
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
204
+
205
+ ^
206
+
207
+ Eitango.java:67: エラー: ';'がありません
208
+
209
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
210
+
211
+ ^
212
+
213
+ Eitango.java:67: エラー: '\u3000'は不正な文字です
214
+
215
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
216
+
217
+ ^
218
+
219
+ Eitango.java:69: エラー: '\u3000'は不正な文字です
220
+
221
+  }
222
+
223
+ ^
224
+
225
+ Eitango.java:69: エラー: ';'がありません
226
+
227
+  }
228
+
229
+ ^
230
+
231
+ Eitango.java:70: エラー: 構文解析中にファイルの終わりに移りました
232
+
167
233
  }
168
234
 
169
- }
235
+ ^
236
+
170
-
237
+ エラー7個
171
-
172
-
238
+
173
- ```
239
+ ```
174
-
175
- ### 試したこと
240
+
176
-
241
+
242
+
177
- 最後に間違った問題の配列番号を読み取って、そ問題番号を出力るために
243
+ どうしても解決方法が思いつかず、配列の処理がわからない状況で
178
-
179
-
180
-
181
- ```
244
+
182
-
183
- else if (ans!=V[i]) errornum = V[i] //for文の中に記入
184
-
185
-
186
-
187
- System.out.println("不正解番号は"+ V[i} + "番でした."); //全体の最後
188
-
189
- ```
190
-
191
- を追記したのですが、コンパイルに失敗ししまいました
245
+ どなか、配列処理方法を教えていただけせんか
192
246
 
193
247
 
194
248
 

1

書式改善、試したが失敗した追加コードの追記

2019/01/19 08:58

投稿

Yuta25jp
Yuta25jp

スコア13

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
 
4
4
 
5
+ javaを使用して「英文の穴埋め」問題を作成しています。
6
+
5
- javaを使用して「英文の穴埋め」問題を作成しています。回答は1〜44択なのですが、最後に間違った問題番号を出力したいです。
7
+ 回答は回答番号1〜4から正解を1つ選ぶ4択なのですが、最後に不正解の問題番号を出力したいです。
6
8
 
7
9
 
8
10
 
@@ -26,130 +28,140 @@
26
28
 
27
29
 
28
30
 
29
- public class Eitango {
30
-
31
- public static void main(String[] args) throws IOException {
32
-
33
- BufferedReader br=
34
-
35
- new BufferedReader(new InputStreamReader(System.in));
36
-
37
- String[] Q=new String[11];
38
-
39
-
40
-
41
- Q[1]="A: Can I borrow your camera ?\n"
42
-
43
- +"B: Sure, but it doesn't ( ) very well."
44
-
45
- +"It's very old.\n"
46
-
47
- +"1,work 2,play 3,speak 4,live";
48
-
49
-
50
-
51
- Q[2]="A: Have you finished your homework, Ken ?\n"
52
-
53
- +"B: No. I'm ( ) doing it.\n"
54
-
55
- +"1,often 2,long 3,still 4,fun ";
56
-
57
-
58
-
59
- Q[3]="A: My name is Christopher, but my friends ( ) me Chris. \n"
60
-
61
- +"1,say 2,call 3,speak 4,tell " ;
62
-
63
-
64
-
65
- Q[4]="A:Kate really ( ) herself last year.\n"
66
-
67
- +"She wants to go there again this year.\n"
68
-
69
- +"1,time 2,enjoyed 3,put 4,passed";
70
-
71
-
72
-
73
- Q[5]="A: Excuse me. I ask you a ( ) ?\n"
74
-
75
- +"B: Sure.\n"
76
-
77
- +"1,sorry 2,favor 3,please 4,door";
78
-
79
-
80
-
81
- Q[6]="A: Hello. This is Sam. Can I speak to Lisa ?\n"
82
-
83
- +"B: ( ). She is out now.\n"
84
-
85
- +"1,Sorry 2,Thanks 3,Great 4,OK";
86
-
87
-
88
-
89
- Q[7]="A: I want be a singer. How ( ) you ?\n"
90
-
91
- +"1,much 2,many 3,about 4,often";
92
-
93
-
94
-
95
- Q[8]="A: Are you free on Sunday ? We'll have a party.\n"
96
-
97
- +"B: Yes. What ( ) ?\n"
98
-
99
- +"A: At noon.\n"
100
-
101
- +"1,time 2,kind 3,party 4,up";
102
-
103
-
104
-
105
- Q[9]="A: We go to school ( ) Monday to Friday. \n"
106
-
107
- +"1,too 2,on 3,in 4,from";
108
-
109
-
110
-
111
- Q[10]="A:What ( ) of music do you like the best ?\n"
112
-
113
- +"B: I like rock music the best.\n"
114
-
115
- +"1,kind 2,time 3,subject 4,place";
116
-
117
-
118
-
119
- int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
120
-
121
- int correct=0,error=0,total=10;
122
-
123
-
124
-
125
- for (int i=1; i<=10; i++) {
126
-
127
- System.out.println(Q[i]); // 問題の表示
128
-
129
- System.out.print("1~4 の番号を入れて下さい=>");
130
-
131
- int ans=Integer.parseInt(br.readLine()); // 回答の入力
132
-
133
- if (ans==V[i])correct++; // 正解場合
134
-
135
- else error++; // 不正解場合
136
-
137
-
138
-
139
- System.out.println();
31
+ public class Eitango
32
+
33
+ {
34
+
35
+ public static void main(String[] args) throws IOException
36
+
37
+ {
38
+
39
+ BufferedReader br=
40
+
41
+ new BufferedReader(new InputStreamReader(System.in));
42
+
43
+ String[] Q=new String[11];
44
+
45
+
46
+
47
+ Q[1]="A: Can I borrow your camera ?\n"
48
+
49
+ +"B: Sure, but it doesn't ( ) very well."
50
+
51
+ +"It's very old.\n"
52
+
53
+ +"1,work 2,play 3,speak 4,live";
54
+
55
+
56
+
57
+ Q[2]="A: Have you finished your homework, Ken ?\n"
58
+
59
+ +"B: No. I'm ( ) doing it.\n"
60
+
61
+ +"1,often 2,long 3,still 4,fun ";
62
+
63
+
64
+
65
+ Q[3]="A: My name is Christopher, but my friends ( ) me Chris. \n"
66
+
67
+ +"1,say 2,call 3,speak 4,tell " ;
68
+
69
+
70
+
71
+ Q[4]="A:Kate really ( ) herself last year.\n"
72
+
73
+ +"She wants to go there again this year.\n"
74
+
75
+ +"1,time 2,enjoyed 3,put 4,passed";
76
+
77
+
78
+
79
+ Q[5]="A: Excuse me. I ask you a ( ) ?\n"
80
+
81
+ +"B: Sure.\n"
82
+
83
+ +"1,sorry 2,favor 3,please 4,door";
84
+
85
+
86
+
87
+ Q[6]="A: Hello. This is Sam. Can I speak to Lisa ?\n"
88
+
89
+ +"B: ( ). She is out now.\n"
90
+
91
+ +"1,Sorry 2,Thanks 3,Great 4,OK";
92
+
93
+
94
+
95
+ Q[7]="A: I want be a singer. How ( ) you ?\n"
96
+
97
+ +"1,much 2,many 3,about 4,often";
98
+
99
+
100
+
101
+ Q[8]="A: Are you free on Sunday ? We'll have a party.\n"
102
+
103
+ +"B: Yes. What ( ) ?\n"
104
+
105
+ +"A: At noon.\n"
106
+
107
+ +"1,time 2,kind 3,party 4,up";
108
+
109
+
110
+
111
+ Q[9]="A: We go to school ( ) Monday to Friday. \n"
112
+
113
+ +"1,too 2,on 3,in 4,from";
114
+
115
+
116
+
117
+ Q[10]="A:What ( ) of music do you like the best ?\n"
118
+
119
+ +"B: I like rock music the best.\n"
120
+
121
+ +"1,kind 2,time 3,subject 4,place";
122
+
123
+
124
+
125
+ int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
126
+
127
+ int correct=0,error=0,total=10;
128
+
129
+
130
+
131
+ for (int i=1; i<=10; i++)
132
+
133
+ {
134
+
135
+ System.out.println(Q[i]); // 問題表示
136
+
137
+ System.out.print("1~4番号を入れて下さい=>");
138
+
139
+ int ans=Integer.parseInt(br.readLine()); // 回答の入力
140
+
141
+ if (ans==V[i])correct++; // 正解の場合
142
+
143
+ else error++; // 不正解の場合
144
+
145
+ System.out.println();
146
+
147
+ }
148
+
149
+
150
+
151
+ System.out.println("10 問中 "+correct+"問正解でした.");
152
+
153
+ int percent = correct * 100 / total;
154
+
155
+ System.out.println("正答率は"+ percent + "%でした.");
156
+
157
+
158
+
159
+
160
+
161
+  }
140
162
 
141
163
  }
142
164
 
143
- System.out.println("10 問中 "+correct+"問正解でした.");
144
-
145
-
146
-
147
- int percent = correct * 100 / total;
148
-
149
- System.out.println("正答率は"+ percent + "%でした.");
150
-
151
-
152
-
153
165
 
154
166
 
155
167
  }
@@ -160,6 +172,24 @@
160
172
 
161
173
  ```
162
174
 
175
+ ### 試したこと
176
+
177
+ 最後に間違った問題の配列番号を読み取って、その問題番号を出力するために
178
+
179
+
180
+
181
+ ```
182
+
183
+ else if (ans!=V[i]) errornum = V[i] //for文の中に記入
184
+
185
+
186
+
187
+ System.out.println("不正解番号は"+ V[i} + "番でした."); //全体の最後
188
+
189
+ ```
190
+
191
+ を追記したのですが、コンパイルに失敗してしまいました。
192
+
163
193
 
164
194
 
165
195