Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
57 lines (37 loc) · 1.47 KB
/
Copy pathMain.java
File metadata and controls
57 lines (37 loc) · 1.47 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
52
53
54
55
56
57
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];
for (int i = 0; i < cars.length; i++) {
String carName;
while (true) {
System.out.print("Введите название машины: ");
carName = scanner.nextLine();
if (!carName.trim().isEmpty()) {
break;
}
System.out.println("Название не может быть пустым.");
}
int speed;
while (true) {
System.out.print("Введите скорость (1-250): ");
String speedInput = scanner.nextLine();
try {
speed = Integer.parseInt(speedInput);
if (speed > 0 && speed <= 250) {
break;
}
System.out.println("Скорость должна быть от 1 до 250.");
} catch (NumberFormatException e) {
System.out.println("Введите целое число.");
}
}
cars[i] = new Car(carName, speed);
}
Race race = new Race(cars);
Car leader = race.findLeader();
System.out.println("Победитель: " + leader.carName);
scanner.close();
}
}