-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathInputHelper.java
More file actions
35 lines (30 loc) · 1.05 KB
/
InputHelper.java
File metadata and controls
35 lines (30 loc) · 1.05 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
29
30
31
32
33
34
35
package lotto;
import java.util.ArrayList;
import java.util.List;
import org.kokodak.Console;
public class InputHelper {
//정수를 입력받는 메소드
public static int getIntInput(String prompt) {
try{
System.out.println(prompt);
int num = Integer.parseInt(Console.readLine());
return num;
} catch (IllegalArgumentException e){
throw new IllegalArgumentException("[ERROR]유효한 숫자를 입력해주세요");
}
}
//리스트를 입력받는 메소드
public static List<Integer> getListInput(String prompt){
List<Integer> list = new ArrayList<>();
System.out.println(prompt);
String line = Console.readLine();
String[] str = line.split(",");
if(str.length == 6){
for(int i = 0; i < str.length; i++){
list.add(Integer.parseInt(str[i]));
}
return list;
}
throw new IllegalArgumentException("[ERROR]당첨숫자의 개수를 잘못 입력했습니다.");
}
}