forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountPeople.java
More file actions
29 lines (24 loc) · 1.07 KB
/
CountPeople.java
File metadata and controls
29 lines (24 loc) · 1.07 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
import java.util.Scanner;
public class CountPeople{
//Функция первой части.
//На сколько людей будем делить счет
public static int countPeopleInput() {
Scanner in = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счет?");
boolean check = true;
int quantity = 0;
while (check) {
if (in.hasNextInt()) {
quantity = in.nextInt();
if (quantity <= 1) {
System.out.println("Вы ошиблись, вы ввели меньше 2, а именно: " + quantity + "\n Пожалуйста повторите ввод.");
} else {
check = false;
}
} else {
System.out.println("Вы ошиблись, вы ввели " + in.next() + " вместо целого числа. \n Пожалуйста повторите ввод.");
}
}
return quantity;
}
}