回答編集履歴

4

ソースの修正

2020/03/11 10:46

投稿

yureighost
yureighost

スコア2183

test CHANGED
@@ -18,17 +18,25 @@
18
18
 
19
19
  answer[i] = (int)(Math.random() * 10) ;
20
20
 
21
- for (int j = i - 1; j >= 0; j--) {
21
+ int j = i - 1;
22
22
 
23
- // 前の桁の数字と異なる場合
23
+ while (j >= 0) {
24
24
 
25
- if (answer[i] != answer[j]){
25
+ // 前の桁の数字と同じ場合
26
26
 
27
- // カウンターiに1加算する
27
+ if (answer[i] == answer[j]){
28
28
 
29
- i++;
29
+ break;
30
30
 
31
31
  }
32
+
33
+ j--;
34
+
35
+ }
36
+
37
+ if (j == -1) {
38
+
39
+ i++;
32
40
 
33
41
  }
34
42
 
@@ -38,6 +46,6 @@
38
46
 
39
47
  Arrays.stream(answer)
40
48
 
41
- .forEach(System.out::print);
49
+ .forEach(System.out::print);
42
50
 
43
51
  ```

3

ソース修正

2020/03/11 10:46

投稿

yureighost
yureighost

スコア2183

test CHANGED
@@ -18,13 +18,17 @@
18
18
 
19
19
  answer[i] = (int)(Math.random() * 10) ;
20
20
 
21
- // 一つ前の桁の数字と異なる場合
21
+ for (int j = i - 1; j >= 0; j--) {
22
22
 
23
- if (answer[i] != answer[i - 1]){
23
+ // 前の桁の数字と異なる場合
24
24
 
25
- // カウンターiに1加算する
25
+ if (answer[i] != answer[j]){
26
26
 
27
+ // カウンターiに1加算する
28
+
27
- i++;
29
+ i++;
30
+
31
+ }
28
32
 
29
33
  }
30
34
 

2

誤字

2020/03/11 08:20

投稿

yureighost
yureighost

スコア2183

test CHANGED
@@ -1,4 +1,4 @@
1
- int配列で前後比較する発は悪くないと思います。
1
+ int配列で前後比較する発は悪くないと思います。
2
2
 
3
3
  ただ何度もループさせるより一桁ずつ確定させてしまった方が簡単ですね。
4
4
 

1

誤字

2020/03/11 07:19

投稿

yureighost
yureighost

スコア2183

test CHANGED
File without changes