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

回答編集履歴

5

乱数範囲変更

2020/01/05 04:30

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -12,22 +12,22 @@
12
12
  Random rand = new Random();
13
13
 
14
14
  //千の位を選ぶ
15
- int sen = rand.nextInt(9);
15
+ int sen = rand.nextInt(10);
16
16
  ans[0] = digits[sen];
17
17
  digits[sen] = digits[9];
18
18
 
19
19
  //百の位を選ぶ
20
- int hyaku = rand.nextInt(8);
20
+ int hyaku = rand.nextInt(9);
21
21
  ans[1] = digits[hyaku];
22
22
  digits[hyaku] = digits[8];
23
23
 
24
24
  //十の位を選ぶ
25
- int zyuu = rand.nextInt(7);
25
+ int zyuu = rand.nextInt(8);
26
26
  ans[2] = digits[zyuu];
27
27
  digits[zyuu] = digits[7];
28
28
 
29
29
  //一の位を選ぶ
30
- int iti = rand.nextInt(6);
30
+ int iti = rand.nextInt(7);
31
31
  ans[3] = digits[iti];
32
32
 
33
33
  //選んだ4個の数を表示

4

コメント修正

2020/01/05 04:30

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -6,10 +6,10 @@
6
6
 
7
7
  public class Main {
8
8
  public static void main(String[] args) {
9
- Random rand = new Random();
10
- //10個の列を作る
9
+ //10個のから4個の数ランダムに選ぶ
11
10
  int[] digits = {0,1,2,3,4,5,6,7,8,9};
12
11
  int[] ans = new int[4];
12
+ Random rand = new Random();
13
13
 
14
14
  //千の位を選ぶ
15
15
  int sen = rand.nextInt(9);
@@ -30,7 +30,7 @@
30
30
  int iti = rand.nextInt(6);
31
31
  ans[3] = digits[iti];
32
32
 
33
- //4桁持ってくる
33
+ //選んだ4個の数を表示
34
34
  System.out.println("" + ans[0] + ans[1] + ans[2] + ans[3]);
35
35
  }
36
36
  }

3

バグ修正

2020/01/05 04:05

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -14,17 +14,17 @@
14
14
  //千の位を選ぶ
15
15
  int sen = rand.nextInt(9);
16
16
  ans[0] = digits[sen];
17
- digits[ans[0]] = digits[9];
17
+ digits[sen] = digits[9];
18
18
 
19
19
  //百の位を選ぶ
20
20
  int hyaku = rand.nextInt(8);
21
21
  ans[1] = digits[hyaku];
22
- digits[ans[1]] = digits[8];
22
+ digits[hyaku] = digits[8];
23
23
 
24
24
  //十の位を選ぶ
25
25
  int zyuu = rand.nextInt(7);
26
26
  ans[2] = digits[zyuu];
27
- digits[ans[2]] = digits[7];
27
+ digits[zyuu] = digits[7];
28
28
 
29
29
  //一の位を選ぶ
30
30
  int iti = rand.nextInt(6);

2

コード整形

2020/01/05 04:01

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -7,7 +7,6 @@
7
7
  public class Main {
8
8
  public static void main(String[] args) {
9
9
  Random rand = new Random();
10
-
11
10
  //10個の配列を作る
12
11
  int[] digits = {0,1,2,3,4,5,6,7,8,9};
13
12
  int[] ans = new int[4];
@@ -15,17 +14,17 @@
15
14
  //千の位を選ぶ
16
15
  int sen = rand.nextInt(9);
17
16
  ans[0] = digits[sen];
18
- digits[ans[0]]= digits[9];
17
+ digits[ans[0]] = digits[9];
19
18
 
20
19
  //百の位を選ぶ
21
20
  int hyaku = rand.nextInt(8);
22
21
  ans[1] = digits[hyaku];
23
- digits[ans[1]]= digits[8];
22
+ digits[ans[1]] = digits[8];
24
23
 
25
24
  //十の位を選ぶ
26
25
  int zyuu = rand.nextInt(7);
27
26
  ans[2] = digits[zyuu];
28
- digits[ans[2]]= digits[7];
27
+ digits[ans[2]] = digits[7];
29
28
 
30
29
  //一の位を選ぶ
31
30
  int iti = rand.nextInt(6);

1

配列確保変更

2020/01/05 03:57

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  //10個の配列を作る
12
12
  int[] digits = {0,1,2,3,4,5,6,7,8,9};
13
- int[] ans = {0,0,0,0};
13
+ int[] ans = new int[4];
14
14
 
15
15
  //千の位を選ぶ
16
16
  int sen = rand.nextInt(9);