質問編集履歴
1
コード内に行数を入力してしまっていたため、削除いたしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,27 +11,27 @@
|
|
11
11
|
|
12
12
|
```Java
|
13
13
|
|
14
|
-
|
14
|
+
public static void main(String[] args) {
|
15
|
-
|
15
|
+
System.out.println("Welcome :)");
|
16
|
-
|
16
|
+
System.out.print("How many dices would you like to roll? Please enter a number:");
|
17
|
-
|
17
|
+
|
18
|
-
|
18
|
+
askAndRollAndSum();
|
19
|
-
6
|
20
|
-
7 while (true) {
|
21
|
-
8 System.out.println("Would you still like to roll the dice(s) again?(Yes or No)");
|
22
|
-
9 Scanner sc = new Scanner(System.in);
|
23
|
-
10 String answer = sc.next();
|
24
|
-
11 if (answer.toLowerCase().equals("yes")) {
|
25
|
-
12 System.out.println("How many dices would you like to roll this time?");
|
26
|
-
13 askAndRollAndSum();
|
27
|
-
14 } else {
|
28
|
-
15 System.out.println("Thank you for your time :)");
|
29
|
-
16 break;
|
30
|
-
17 }
|
31
|
-
18 }
|
32
|
-
19 }
|
33
|
-
20
|
34
19
|
|
20
|
+
while (true) {
|
21
|
+
System.out.println("Would you still like to roll the dice(s) again?(Yes or No)");
|
22
|
+
Scanner sc = new Scanner(System.in);
|
23
|
+
String answer = sc.next();
|
24
|
+
if (answer.toLowerCase().equals("yes")) {
|
25
|
+
System.out.println("How many dices would you like to roll this time?");
|
26
|
+
askAndRollAndSum();
|
27
|
+
} else {
|
28
|
+
System.out.println("Thank you for your time :)");
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
35
|
```
|
36
36
|
|
37
37
|
|
@@ -40,28 +40,28 @@
|
|
40
40
|
###問題のメソッド
|
41
41
|
|
42
42
|
```Java
|
43
|
-
|
43
|
+
public static void askAndRollAndSum() {
|
44
|
-
|
44
|
+
while (true) {
|
45
|
-
|
45
|
+
int sum = 0;
|
46
|
-
|
46
|
+
Scanner sc = new Scanner(System.in);
|
47
|
-
|
47
|
+
int numberOfDices = sc.nextInt();
|
48
|
-
|
48
|
+
if (numberOfDices <= 0) {
|
49
|
-
|
49
|
+
System.out.println("Please enter a number bigger than 0");
|
50
|
-
|
50
|
+
numberOfDices = sc.nextInt();
|
51
|
-
|
51
|
+
if (numberOfDices <= 0) {
|
52
|
-
|
52
|
+
System.out.println("Please try again! Sorry :(");
|
53
|
-
|
53
|
+
break;
|
54
|
-
32 }
|
55
|
-
|
54
|
+
}
|
55
|
+
}
|
56
|
-
|
56
|
+
for (int i = 0; i < numberOfDices; i++) {
|
57
|
-
|
57
|
+
int resultOfThisTime = valueOfDice();
|
58
|
-
|
58
|
+
System.out.println(resultOfThisTime);
|
59
|
-
|
59
|
+
sum += resultOfThisTime;
|
60
|
-
|
60
|
+
}
|
61
|
-
|
61
|
+
System.out.println("Total: " + sum);
|
62
|
-
40 }
|
63
|
-
|
62
|
+
}
|
64
|
-
|
63
|
+
}
|
64
|
+
|
65
65
|
```
|
66
66
|
|
67
67
|
|
@@ -69,11 +69,11 @@
|
|
69
69
|
|
70
70
|
###問題の起きていないメソッド
|
71
71
|
```Java
|
72
|
-
|
72
|
+
public static int valueOfDice() {
|
73
|
-
|
73
|
+
Random rand = new Random();
|
74
|
-
|
74
|
+
int result = rand.nextInt(6) + 1;
|
75
|
-
|
75
|
+
return result;
|
76
|
-
|
76
|
+
}
|
77
77
|
|
78
78
|
```
|
79
79
|
|
@@ -108,7 +108,7 @@
|
|
108
108
|
Thank you for your time :)
|
109
109
|
```
|
110
110
|
|
111
|
-
一度想定通りうまくにいったのですが、色々と細かいところをいじっていたら、5行目のaskAndRollAndSum();の後の処理が行われないようになってしまいました。
|
111
|
+
一度想定通りうまくにいったのですが、色々と細かいところをいじっていたら、メインメソッド5行目のaskAndRollAndSum();の後の処理が行われないようになってしまいました。
|
112
112
|
試しに、問題のメソッドの代わりに、問題の起きていないメソッドを5行目にて実行・printしてみたのですが、こちらは問題なくその後の処理も行われました。
|
113
113
|
|
114
114
|
Eclipse IDE for Java Developers(4.18.0)を使っています。
|