回答編集履歴

2

ちょっとだけリファクタ

2018/04/18 13:31

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```Java
4
4
 
5
- import java.util.*;
5
+ import java.util.Scanner;
6
6
 
7
7
 
8
8
 
@@ -14,13 +14,11 @@
14
14
 
15
15
  try {
16
16
 
17
- return sc.nextInt();
17
+ return Integer.parseInt(sc.nextLine());
18
18
 
19
19
  }
20
20
 
21
- catch(InputMismatchException e) {
21
+ catch(NumberFormatException e) {
22
-
23
- sc.nextLine();
24
22
 
25
23
  System.out.print(message);
26
24
 
@@ -30,7 +28,7 @@
30
28
 
31
29
  }
32
30
 
33
-
31
+
34
32
 
35
33
  public static void main(String[] args) {
36
34
 

1

なんとなくメソッド名が気に入らなかった

2018/04/18 13:31

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  class Main {
10
10
 
11
- static int scanInt(Scanner sc, String message) {
11
+ static int inputInt(Scanner sc, String message) {
12
12
 
13
13
  while(true) {
14
14
 
@@ -46,7 +46,7 @@
46
46
 
47
47
  System.out.print(message);
48
48
 
49
- playCount = scanInt(sc, message);
49
+ playCount = inputInt(sc, message);
50
50
 
51
51
  }
52
52