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

回答編集履歴

4

ソースの修正

2020/03/11 10:46

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -8,15 +8,19 @@
8
8
  // 1から3まで繰り返す(answer[1~3]まで処理を行う)
9
9
  while (i < answer.length) {
10
10
  answer[i] = (int)(Math.random() * 10) ;
11
+ int j = i - 1;
11
- for (int j = i - 1; j >= 0; j--) {
12
+ while (j >= 0) {
12
- // 前の桁の数字と異なる場合
13
+ // 前の桁の数字と同じ場合
13
- if (answer[i] != answer[j]){
14
+ if (answer[i] == answer[j]){
14
- // カウンターiに1加算する
15
- i++;
15
+ break;
16
16
  }
17
+ j--;
17
18
  }
19
+ if (j == -1) {
20
+ i++;
21
+ }
18
22
  }
19
23
  // int配列を一文字ずつ出力
20
24
  Arrays.stream(answer)
21
- .forEach(System.out::print);
25
+ .forEach(System.out::print);
22
26
  ```

3

ソース修正

2020/03/11 10:46

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -8,10 +8,12 @@
8
8
  // 1から3まで繰り返す(answer[1~3]まで処理を行う)
9
9
  while (i < answer.length) {
10
10
  answer[i] = (int)(Math.random() * 10) ;
11
+ for (int j = i - 1; j >= 0; j--) {
11
- // 一つ前の桁の数字と異なる場合
12
+ // 前の桁の数字と異なる場合
12
- if (answer[i] != answer[i - 1]){
13
+ if (answer[i] != answer[j]){
13
- // カウンターiに1加算する
14
+ // カウンターiに1加算する
14
- i++;
15
+ i++;
16
+ }
15
17
  }
16
18
  }
17
19
  // int配列を一文字ずつ出力

2

誤字

2020/03/11 08:20

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -1,4 +1,4 @@
1
- int配列で前後比較する発は悪くないと思います。
1
+ int配列で前後比較する発は悪くないと思います。
2
2
  ただ何度もループさせるより一桁ずつ確定させてしまった方が簡単ですね。
3
3
  ```java
4
4
  System.out.println("ゲームを始めます");

1

誤字

2020/03/11 07:19

投稿

yureighost
yureighost

スコア2183

answer CHANGED
File without changes