forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInput.java
More file actions
23 lines (21 loc) · 780 Bytes
/
UserInput.java
File metadata and controls
23 lines (21 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
public class UserInput {
private static Scanner scanner;
public static int readUsersNumber() {
scanner = new Scanner(System.in);
System.out.println("Введите количество пользователей:");
while(!scanner.hasNextInt()) {
System.out.println("Введите число");
scanner.next();
}
int usersNumber = scanner.nextInt();
return getValidNumber(usersNumber);
}
private static int getValidNumber(int usersNumber) {
while(usersNumber <= 1) {
System.out.println("Введите количество людей больше 1");
usersNumber = scanner.nextInt();
}
return usersNumber;
}
}