Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (43 loc) · 1.63 KB
/
Copy pathMain.java
File metadata and controls
51 lines (43 loc) · 1.63 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = 0;
Race racer = new Race();
while(true){
System.out.println("Введите количество машин:");
if(scanner.hasNextInt()){
count = scanner.nextInt();
scanner.nextLine();
if(count > 0) {
break;
}
}
else {
System.out.println("Ошибка ввода! Попробуйте снова!");
scanner.next();
}
}
for(int i = 0; i < count; i++) {
System.out.println("Введите название " + (i+1) + "-ой машины:");
String nameCar = scanner.nextLine();
int speedCar;
while (true) {
System.out.println("Введите скорость " + (i+1) + "-ой машины(больше 0 и меньше 250):");
if (scanner.hasNextInt()) {
speedCar = scanner.nextInt();
scanner.nextLine();
if( speedCar > 0 && speedCar < 250) {
racer.checkRacer(nameCar, speedCar);
break;
}
} else {
System.out.println("Неправильная скорость!");
scanner.next();
}
}
}
System.out.println("Победитель: " + racer.getRace());
scanner.close();
}
}