forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuests.java
More file actions
26 lines (23 loc) · 961 Bytes
/
Guests.java
File metadata and controls
26 lines (23 loc) · 961 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
import java.util.Scanner;
class Guests {
public static int gettingToKnowNumberOfGuests() {
Scanner scanner = new Scanner(System.in);
int number = 0;
while (true) {
System.out.println("Введите кол-во гостей, на которых нужно разделить счет");
while (!scanner.hasNextInt()) {
System.out.println("Ошибка! Вы ввели текст! Вам нужно ввести целое число.");
scanner.next();
}
number = scanner.nextInt();
if (number > 1) {
break;
} else if (number < 0) {
System.out.println("Кол-во гостей не может быть отрицательынм");
} else {
System.out.println("Кол-во гостей не может быть меньше 1");
}
}
return number;
}
}