質問編集履歴
5
ソースの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -55,7 +55,7 @@
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
}
|
58
|
-
List<Integer> result = new ArrayList<>();
|
58
|
+
List<Integer> result = new ArrayList<Integer>();
|
59
59
|
for(int a : answer){
|
60
60
|
for(int b : input){
|
61
61
|
if(a == b){
|
4
ソース修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -55,7 +55,7 @@
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
}
|
58
|
-
List<Integer> result = new ArrayList<
|
58
|
+
List<Integer> result = new ArrayList<>();
|
59
59
|
for(int a : answer){
|
60
60
|
for(int b : input){
|
61
61
|
if(a == b){
|
3
前提と実現の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
乱数と入力した4桁の数字の配列をfor文で回して同じ桁に同じ数字がある場合〇違う桁に同じ数字がある場合△と
|
2
|
+
乱数と入力した4桁の数字の配列をfor文で回して同じ桁に同じ数字がある場合〇違う桁に同じ数字がある場合△となるプログラムを作りたいのですがforまでいかず
|
3
|
-
|
3
|
+
数字を入力して無限ループになります
|
4
4
|
|
5
5
|
### 該当のソースコード
|
6
6
|
|
2
ソースを修正しコンパイルは通るのですが入力から先に行けず無限ループになってしまいます
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,9 +12,10 @@
|
|
12
12
|
import java.util.List;
|
13
13
|
import java.util.Scanner;
|
14
14
|
|
15
|
-
public class
|
15
|
+
public class MathGame {
|
16
16
|
|
17
17
|
public static void main(String[] args) {
|
18
|
+
// TODO 自動生成されたメソッド・スタブ
|
18
19
|
System.out.println("ゲームを始めます");
|
19
20
|
int answer[] = new int[4];
|
20
21
|
answer[0] = (int) (Math.random() * 9) + 1;
|
@@ -38,45 +39,35 @@
|
|
38
39
|
}
|
39
40
|
Arrays.stream(answer).forEach(System.out::println);
|
40
41
|
|
41
|
-
int
|
42
|
+
int input[] = new int[4];
|
42
43
|
boolean validated = false;
|
43
44
|
while (!validated) {
|
44
45
|
int a = 0;
|
45
|
-
for (int n = 0; a <
|
46
|
+
for (int n = 0; a < input.length; a++) {
|
46
47
|
System.out.println("4文字の数字を入力してください");
|
47
|
-
String
|
48
|
+
String sc = new Scanner(System.in).nextLine();
|
48
|
-
if (
|
49
|
+
if (sc.length() == 4) {
|
49
50
|
System.out.println("4文字だけ入力されました。");
|
50
51
|
validated = true;
|
51
52
|
} else {
|
52
53
|
System.out.println("4文字だけ入力してください。");
|
54
|
+
break;
|
53
55
|
}
|
54
|
-
List<String> reList = new ArrayList<String>();
|
55
|
-
for(int r : answer ){
|
56
|
-
for(String b : input)
|
57
|
-
if(a.equals(b)){
|
58
|
-
result .add(a);
|
59
|
-
|
56
|
+
}
|
60
57
|
}
|
58
|
+
List<Integer> result = new ArrayList<Integer>();
|
59
|
+
for(int a : answer){
|
60
|
+
for(int b : input){
|
61
|
+
if(a == b){
|
62
|
+
result.add(a);
|
61
|
-
|
63
|
+
break;
|
62
64
|
}
|
63
65
|
}
|
64
|
-
System.out.println("ListA = " + answer);
|
65
|
-
System.out.println("ListB = " + input);
|
66
|
-
System.out.println("ListC = " + result);
|
67
66
|
}
|
67
|
+
System.out.println("ListA = " + answer);
|
68
|
+
System.out.println("ListB = " + input);
|
69
|
+
System.out.println("ListC = " + result);
|
68
|
-
|
70
|
+
}
|
69
|
-
}
|
71
|
+
}
|
70
72
|
|
71
|
-
```
|
72
|
-
```
|
73
|
-
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
|
74
|
-
java.lang.Iterable の配列またはインスタンスのみ繰り返すことができます
|
75
|
-
equals(String) を基本タイプ int で起動できません
|
76
|
-
result を解決できません
|
77
|
-
b を変数に解決できません
|
78
|
-
result を変数に解決できません
|
79
|
-
|
80
|
-
at game.MathGame.main(MathGame.java:50)
|
81
|
-
|
82
73
|
```
|
1
コンパイルエラーです
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,4 +67,16 @@
|
|
67
67
|
}
|
68
68
|
}
|
69
69
|
}
|
70
|
+
|
71
|
+
```
|
72
|
+
```
|
73
|
+
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
|
74
|
+
java.lang.Iterable の配列またはインスタンスのみ繰り返すことができます
|
75
|
+
equals(String) を基本タイプ int で起動できません
|
76
|
+
result を解決できません
|
77
|
+
b を変数に解決できません
|
78
|
+
result を変数に解決できません
|
79
|
+
|
80
|
+
at game.MathGame.main(MathGame.java:50)
|
81
|
+
|
70
82
|
```
|