回答編集履歴
2
ちょっとだけリファクタ
answer
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
こんなのはどうでしょう。
|
2
2
|
```Java
|
3
|
-
import java.util.
|
3
|
+
import java.util.Scanner;
|
4
4
|
|
5
5
|
class Main {
|
6
6
|
static int inputInt(Scanner sc, String message) {
|
7
7
|
while(true) {
|
8
8
|
try {
|
9
|
-
return sc.
|
9
|
+
return Integer.parseInt(sc.nextLine());
|
10
10
|
}
|
11
|
-
catch(
|
11
|
+
catch(NumberFormatException e) {
|
12
|
-
sc.nextLine();
|
13
12
|
System.out.print(message);
|
14
13
|
}
|
15
14
|
}
|
16
15
|
}
|
17
|
-
|
16
|
+
|
18
17
|
public static void main(String[] args) {
|
19
18
|
try(Scanner sc = new Scanner(System.in)) {
|
20
19
|
int playCount = -1;
|
1
なんとなくメソッド名が気に入らなかった
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import java.util.*;
|
4
4
|
|
5
5
|
class Main {
|
6
|
-
static int
|
6
|
+
static int inputInt(Scanner sc, String message) {
|
7
7
|
while(true) {
|
8
8
|
try {
|
9
9
|
return sc.nextInt();
|
@@ -22,7 +22,7 @@
|
|
22
22
|
String message = "ゲーム回数は1回以上です。\nゲーム回数を入力してください\n";
|
23
23
|
|
24
24
|
System.out.print(message);
|
25
|
-
playCount =
|
25
|
+
playCount = inputInt(sc, message);
|
26
26
|
}
|
27
27
|
|
28
28
|
System.out.println("playCountは" + playCount + "です。");
|