-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathInputController.java
More file actions
33 lines (30 loc) · 1017 Bytes
/
InputController.java
File metadata and controls
33 lines (30 loc) · 1017 Bytes
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
package controller;
import java.util.*;
public class InputController {
public ArrayList<Integer> generateUserNum() {
ArrayList<Integer> userNumber = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
System.out.print("숫자를 입력하세요: ");
for (int i = 0; i < 3; i++) {
if (scanner.hasNextInt()) {
userNumber.add(scanner.nextInt());
} else {
scanner.next();
i = 0;
}
}
if(userNumber.stream().anyMatch(x->x>9)){
System.out.println("한자리 수만 입력할 수 있습니다. 다시 입력해주세요");
userNumber.clear();
}
return userNumber;
}
public Set<Integer> generateComputerNum() {
Set<Integer> numbers = new LinkedHashSet<>();
Random random = new Random();
while (numbers.size() < 3) {
numbers.add(random.nextInt(1, 10));
}
return numbers;
}
}