Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ver2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MaxM-V wants to merge 5 commits into main
base: main
Choose a base branch
Loading
from dev
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner sc = new Scanner(System.in);
String name;
int speed;
int cars = 3;
for (int i = 0; i<cars; i++){
Car car = new Car ();
System.out.println("Введите название "+ (i+1) + " автомобиля");
name = sc.nextLine();
car.name = name;
while (true){
System.out.println("Введите скорость от 0 до 250 км в ч "+ (i+1) + " автомобиля");
try {speed = Integer.parseInt(sc.nextLine());
} catch (Exception e){
System.out.println("Не верное значение, попробуйте еще раз");
continue;
}
if (speed>0 && speed<= 250){
break;
} else {
System.out.println("Не верное значение, попробуйте еще раз");
}
}
car.name =name;
car.speed = speed;

Race.raceLeader(car.name, car.speed);
}
System.out.println("Самая быстрая машина: "+Race.nameLeader);
sc.close();
}


}


class Car {
String name;
int speed;
}
class Race {
static String nameLeader;
static int distance = 0;
public static void raceLeader (String name1, int speed1){
if (speed1*24> distance){
distance = speed1*24;
nameLeader = name1;
}
}
}

AltStyle によって変換されたページ (->オリジナル) /