回答編集履歴
2
rundaom インスタンを1つにした
answer
CHANGED
@@ -11,11 +11,11 @@
|
|
11
11
|
|
12
12
|
public class Gohkaku {
|
13
13
|
public static void main(String[] args) {
|
14
|
+
Random rnd = new Random();
|
14
|
-
while(!hantei()) {}
|
15
|
+
while(!hantei(rnd)) {}
|
15
16
|
}
|
16
17
|
|
17
|
-
static boolean hantei() {
|
18
|
+
static boolean hantei(Random rnd) {
|
18
|
-
Random rnd = new Random();
|
19
19
|
int[] score = {
|
20
20
|
rnd.nextInt(51), // math
|
21
21
|
rnd.nextInt(51), // japanese
|
1
乱数生成部分を変更
answer
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
処理を関数にして、その関数の呼び出しを while で繰り返すようにしてみました。
|
2
|
+
|
2
3
|
また スコアの生成や合計計算部分は、質問文のままでも動作しますが、すこし書き換えてみました。
|
3
4
|
(無駄な変数をなくした、科目の数が増えても書き開ける部分がすくなくなるようにした)
|
5
|
+
乱数の生成部分も他の方の回答の内容を反映させています。
|
4
6
|
|
5
7
|
```java
|
6
8
|
import java.util.Arrays;
|
7
9
|
import java.util.stream.IntStream;
|
10
|
+
import java.util.Random;
|
8
11
|
|
9
12
|
public class Gohkaku {
|
10
13
|
public static void main(String[] args) {
|
@@ -12,11 +15,12 @@
|
|
12
15
|
}
|
13
16
|
|
14
17
|
static boolean hantei() {
|
18
|
+
Random rnd = new Random();
|
15
19
|
int[] score = {
|
16
|
-
|
20
|
+
rnd.nextInt(51), // math
|
17
|
-
|
21
|
+
rnd.nextInt(51), // japanese
|
18
|
-
|
22
|
+
rnd.nextInt(51), // sicence
|
19
|
-
|
23
|
+
rnd.nextInt(51), // social
|
20
24
|
};
|
21
25
|
// int sum = score[0] + score[1] + score[2] + score[3];
|
22
26
|
IntStream intStream = Arrays.stream(score);
|