Skip to content

Conversation

@xabko
Copy link
Owner

@xabko xabko commented Nov 2, 2025

/

public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее

speed = Integer.parseInt(input);

// Проверяем диапазон
if (speed <= 0 || speed > 250) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода


try {
// Проверяем на дробное число
if (input.contains(".") || input.contains(",")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уже есть обработка NumberFormatException , поэтому от этой проверки можно отказаться

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants