forked from woowacourse-precourse/java-baseball-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathInputHandler.java
More file actions
28 lines (25 loc) · 1 KB
/
InputHandler.java
File metadata and controls
28 lines (25 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package baseball;
import java.util.*;
import camp.nextstep.edu.missionutils.Randoms;
public class InputHandler {
public static List<Integer> getUserInput() {
try {
System.out.print("숫자를 입력해주세요 : ");
String inputUserNum = camp.nextstep.edu.missionutils.Console.readLine();
if (inputUserNum == null || inputUserNum.length() != 3) {
throw new IllegalArgumentException();
}
List<Integer> userInput = new ArrayList<>();
for (char digitChar : inputUserNum.toCharArray()) {
int digit = Character.getNumericValue(digitChar);
if (digit < 1 || digit > 9) {
throw new IllegalArgumentException();
}
userInput.add(digit);
}
return userInput;
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("잘못된 입력입니다. 다시 시도해주세요.");
}
}
}