質問するログイン新規登録

質問編集履歴

2

エラー内容併記

2019/01/19 08:58

投稿

Yuta25jp
Yuta25jp

スコア13

title CHANGED
@@ -1,1 +1,1 @@
1
- Javaで間違い回答番号を出力したいです。
1
+ Javaで間違い回答番号を出力したいです。[配列処理に困っている]
body CHANGED
@@ -61,7 +61,7 @@
61
61
  +"1,kind 2,time 3,subject 4,place";
62
62
 
63
63
  int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
64
- int correct=0,error=0,total=10;
64
+ int correct=0,error=0,errornum,total=10;
65
65
 
66
66
  for (int i=1; i<=10; i++)
67
67
  {
@@ -69,6 +69,7 @@
69
69
  System.out.print("1~4 の番号を入れて下さい=>");
70
70
  int ans=Integer.parseInt(br.readLine()); // 回答の入力
71
71
  if (ans==V[i])correct++; // 正解の場合
72
+ else if (ans!=V[i]) errornum = V[i];
72
73
  else error++; // 不正解の場合
73
74
  System.out.println();
74
75
  }
@@ -76,26 +77,52 @@
76
77
  System.out.println("10 問中 "+correct+"問正解でした.");
77
78
  int percent = correct * 100 / total;
78
79
  System.out.println("正答率は"+ percent + "%でした.");
80
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
79
81
 
80
-
81
82
   }
82
83
  }
83
84
 
84
- }
85
- }
86
85
 
87
86
  ```
88
87
  ### 試したこと
89
- 最後に間違った問題の配列番号を読み取って、その問題番号を出力するために
90
88
 
89
+ 間違った問題の配列番号を読み取って、その問題番号を出力するために
90
+
91
91
  ```
92
92
  else if (ans!=V[i]) errornum = V[i] //for文の中に記入
93
-
94
93
  System.out.println("不正解番号は"+ V[i} + "番でした."); //全体の最後
95
94
  ```
96
- 記しのですが、コンパイルに失敗してしまいました。
95
+ を記ているのですが、コンパイルに失敗してしまい、下記のエラーが表示されました。
97
96
 
97
+ ```
98
+ Eitango.java:67: エラー: ']'がありません
99
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
100
+ ^
101
+ Eitango.java:67: エラー: 文ではありません
102
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
103
+ ^
104
+ Eitango.java:67: エラー: ';'がありません
105
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
106
+ ^
107
+ Eitango.java:67: エラー: '\u3000'は不正な文字です
108
+ System.out.println("不正解番号は"+ V[i} + "番でした."); 
109
+ ^
110
+ Eitango.java:69: エラー: '\u3000'は不正な文字です
111
+  }
112
+ ^
113
+ Eitango.java:69: エラー: ';'がありません
114
+  }
115
+ ^
116
+ Eitango.java:70: エラー: 構文解析中にファイルの終わりに移りました
117
+ }
118
+ ^
119
+ エラー7個
120
+ ```
98
121
 
122
+ どうしても解決方法が思いつかず、配列の処理がわからない状況です。
123
+ どなたか、配列の処理方法を教えていただけませんか。
124
+
125
+
99
126
  ### 補足情報(FW/ツールのバージョンなど)
100
127
  エディター:Atom
101
128
  PC:Mac

1

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

2019/01/19 08:58

投稿

Yuta25jp
Yuta25jp

スコア13

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,7 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
+ javaを使用して「英文の穴埋め」問題を作成しています。
3
- javaを使用して「英文の穴埋め」問題を作成しています。回答は1〜44択なのですが、最後に間違った問題番号を出力したいです。
4
+ 回答は回答番号1〜4から正解を1つ選ぶ4択なのですが、最後に不正解の問題番号を出力したいです。
4
5
 
5
6
  ### 発生している問題・エラーメッセージ
6
7
 
@@ -12,75 +13,89 @@
12
13
  ```Java
13
14
  import java.io.*;
14
15
 
15
- public class Eitango {
16
+ public class Eitango
17
+ {
16
- public static void main(String[] args) throws IOException {
18
+ public static void main(String[] args) throws IOException
19
+ {
17
- BufferedReader br=
20
+ BufferedReader br=
18
- new BufferedReader(new InputStreamReader(System.in));
21
+ new BufferedReader(new InputStreamReader(System.in));
19
- String[] Q=new String[11];
22
+ String[] Q=new String[11];
20
23
 
21
- Q[1]="A: Can I borrow your camera ?\n"
24
+ Q[1]="A: Can I borrow your camera ?\n"
22
- +"B: Sure, but it doesn't ( ) very well."
25
+ +"B: Sure, but it doesn't ( ) very well."
23
- +"It's very old.\n"
26
+ +"It's very old.\n"
24
- +"1,work 2,play 3,speak 4,live";
27
+ +"1,work 2,play 3,speak 4,live";
25
28
 
26
- Q[2]="A: Have you finished your homework, Ken ?\n"
29
+ Q[2]="A: Have you finished your homework, Ken ?\n"
27
- +"B: No. I'm ( ) doing it.\n"
30
+ +"B: No. I'm ( ) doing it.\n"
28
- +"1,often 2,long 3,still 4,fun ";
31
+ +"1,often 2,long 3,still 4,fun ";
29
32
 
30
- Q[3]="A: My name is Christopher, but my friends ( ) me Chris. \n"
33
+ Q[3]="A: My name is Christopher, but my friends ( ) me Chris. \n"
31
- +"1,say 2,call 3,speak 4,tell " ;
34
+ +"1,say 2,call 3,speak 4,tell " ;
32
35
 
33
- Q[4]="A:Kate really ( ) herself last year.\n"
36
+ Q[4]="A:Kate really ( ) herself last year.\n"
34
- +"She wants to go there again this year.\n"
37
+ +"She wants to go there again this year.\n"
35
- +"1,time 2,enjoyed 3,put 4,passed";
38
+ +"1,time 2,enjoyed 3,put 4,passed";
36
39
 
37
- Q[5]="A: Excuse me. I ask you a ( ) ?\n"
40
+ Q[5]="A: Excuse me. I ask you a ( ) ?\n"
38
- +"B: Sure.\n"
41
+ +"B: Sure.\n"
39
- +"1,sorry 2,favor 3,please 4,door";
42
+ +"1,sorry 2,favor 3,please 4,door";
40
43
 
41
- Q[6]="A: Hello. This is Sam. Can I speak to Lisa ?\n"
44
+ Q[6]="A: Hello. This is Sam. Can I speak to Lisa ?\n"
42
- +"B: ( ). She is out now.\n"
45
+ +"B: ( ). She is out now.\n"
43
- +"1,Sorry 2,Thanks 3,Great 4,OK";
46
+ +"1,Sorry 2,Thanks 3,Great 4,OK";
44
47
 
45
- Q[7]="A: I want be a singer. How ( ) you ?\n"
48
+ Q[7]="A: I want be a singer. How ( ) you ?\n"
46
- +"1,much 2,many 3,about 4,often";
49
+ +"1,much 2,many 3,about 4,often";
47
50
 
48
- Q[8]="A: Are you free on Sunday ? We'll have a party.\n"
51
+ Q[8]="A: Are you free on Sunday ? We'll have a party.\n"
49
- +"B: Yes. What ( ) ?\n"
52
+ +"B: Yes. What ( ) ?\n"
50
- +"A: At noon.\n"
53
+ +"A: At noon.\n"
51
- +"1,time 2,kind 3,party 4,up";
54
+ +"1,time 2,kind 3,party 4,up";
52
55
 
53
- Q[9]="A: We go to school ( ) Monday to Friday. \n"
56
+ Q[9]="A: We go to school ( ) Monday to Friday. \n"
54
- +"1,too 2,on 3,in 4,from";
57
+ +"1,too 2,on 3,in 4,from";
55
58
 
56
- Q[10]="A:What ( ) of music do you like the best ?\n"
59
+ Q[10]="A:What ( ) of music do you like the best ?\n"
57
- +"B: I like rock music the best.\n"
60
+ +"B: I like rock music the best.\n"
58
- +"1,kind 2,time 3,subject 4,place";
61
+ +"1,kind 2,time 3,subject 4,place";
59
62
 
60
- int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
63
+ int[] V={ 0, 1, 3, 2, 2, 2, 1, 2, 1, 4, 1}; // 解答リスト
61
- int correct=0,error=0,total=10;
64
+ int correct=0,error=0,total=10;
62
65
 
63
- for (int i=1; i<=10; i++) {
66
+ for (int i=1; i<=10; i++)
67
+ {
64
- System.out.println(Q[i]); // 問題の表示
68
+ System.out.println(Q[i]); // 問題の表示
65
- System.out.print("1~4 の番号を入れて下さい=>");
69
+ System.out.print("1~4 の番号を入れて下さい=>");
66
- int ans=Integer.parseInt(br.readLine()); // 回答の入力
70
+ int ans=Integer.parseInt(br.readLine()); // 回答の入力
67
- if (ans==V[i])correct++; // 正解の場合
71
+ if (ans==V[i])correct++; // 正解の場合
68
- else error++; // 不正解の場合
72
+ else error++; // 不正解の場合
73
+ System.out.println();
74
+ }
69
75
 
70
- System.out.println();
71
- }
72
- System.out.println("10 問中 "+correct+"問正解でした.");
76
+ System.out.println("10 問中 "+correct+"問正解でした.");
77
+ int percent = correct * 100 / total;
78
+ System.out.println("正答率は"+ percent + "%でした.");
73
79
 
74
- int percent = correct * 100 / total;
75
- System.out.println("正答率は"+ percent + "%でした.");
76
80
 
81
+  }
82
+ }
77
83
 
78
84
  }
79
85
  }
80
86
 
81
87
  ```
88
+ ### 試したこと
89
+ 最後に間違った問題の配列番号を読み取って、その問題番号を出力するために
82
90
 
91
+ ```
92
+ else if (ans!=V[i]) errornum = V[i] //for文の中に記入
83
93
 
94
+ System.out.println("不正解番号は"+ V[i} + "番でした."); //全体の最後
95
+ ```
96
+ を追記したのですが、コンパイルに失敗してしまいました。
97
+
98
+
84
99
  ### 補足情報(FW/ツールのバージョンなど)
85
100
  エディター:Atom
86
101
  PC:Mac