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

質問編集履歴

1

コード内に行数を入力してしまっていたため、削除いたしました。

2021/01/22 02:37

投稿

Irina
Irina

スコア1

title CHANGED
File without changes
body CHANGED
@@ -11,27 +11,27 @@
11
11
 
12
12
  ```Java
13
13
 
14
- 1 public static void main(String[] args) {
14
+ public static void main(String[] args) {
15
- 2 System.out.println("Welcome :)");
15
+ System.out.println("Welcome :)");
16
- 3 System.out.print("How many dices would you like to roll? Please enter a number:");
16
+ System.out.print("How many dices would you like to roll? Please enter a number:");
17
- 4
17
+
18
- 5 askAndRollAndSum();
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
- 21 public static void askAndRollAndSum() {
43
+ public static void askAndRollAndSum() {
44
- 22 while (true) {
44
+ while (true) {
45
- 23 int sum = 0;
45
+ int sum = 0;
46
- 24 Scanner sc = new Scanner(System.in);
46
+ Scanner sc = new Scanner(System.in);
47
- 25 int numberOfDices = sc.nextInt();
47
+ int numberOfDices = sc.nextInt();
48
- 26 if (numberOfDices <= 0) {
48
+ if (numberOfDices <= 0) {
49
- 27 System.out.println("Please enter a number bigger than 0");
49
+ System.out.println("Please enter a number bigger than 0");
50
- 28 numberOfDices = sc.nextInt();
50
+ numberOfDices = sc.nextInt();
51
- 29 if (numberOfDices <= 0) {
51
+ if (numberOfDices <= 0) {
52
- 30 System.out.println("Please try again! Sorry :(");
52
+ System.out.println("Please try again! Sorry :(");
53
- 31 break;
53
+ break;
54
- 32 }
55
- 33 }
54
+ }
55
+ }
56
- 34 for (int i = 0; i < numberOfDices; i++) {
56
+ for (int i = 0; i < numberOfDices; i++) {
57
- 35 int resultOfThisTime = valueOfDice();
57
+ int resultOfThisTime = valueOfDice();
58
- 36 System.out.println(resultOfThisTime);
58
+ System.out.println(resultOfThisTime);
59
- 37 sum += resultOfThisTime;
59
+ sum += resultOfThisTime;
60
- 38 }
60
+ }
61
- 39 System.out.println("Total: " + sum);
61
+ System.out.println("Total: " + sum);
62
- 40 }
63
- 41 }
62
+ }
64
- 42
63
+ }
64
+
65
65
  ```
66
66
 
67
67
 
@@ -69,11 +69,11 @@
69
69
 
70
70
  ###問題の起きていないメソッド
71
71
  ```Java
72
- 43 public static int valueOfDice() {
72
+ public static int valueOfDice() {
73
- 44 Random rand = new Random();
73
+ Random rand = new Random();
74
- 45 int result = rand.nextInt(6) + 1;
74
+ int result = rand.nextInt(6) + 1;
75
- 46 return result;
75
+ return result;
76
- 47 }
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)を使っています。