forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonCount.java
More file actions
28 lines (27 loc) · 1.17 KB
/
PersonCount.java
File metadata and controls
28 lines (27 loc) · 1.17 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 PersonCount {
public int personCount(Scanner userInput) {
int userCount;
int circleStep = 0;
System.out.println("Привет! Будем платить сообща? Введи количество участников:");
if (!userInput.hasNextInt()) {
System.out.println("Пожалуйста, используйте только числа при вводе!!!");
Scanner newInput = new Scanner(System.in);
++circleStep;
userCount = personCount(newInput);
} else {
userCount = userInput.nextInt();
}
if (userCount < 1) {
System.out.println("Количество участников не может быть меньше одной персоны, попробуй снова…");
++circleStep;
userCount = personCount(userInput);
} else if (userCount == 1) {
if (circleStep == 0) {
System.out.println("Счёт будет рассчитан на одну персону.");
}
userCount = 1;
}
return userCount;
}
}