Skip to content

я пытаюсь... - #1

Open
azotGr wants to merge 1 commit into
mainfrom
dev
Open

azotGr wants to merge 1 commit into
mainfrom
dev

Conversation

@azotGr

@azotGr azotGr commented Oct 23, 2023

Copy link
Copy Markdown
Owner

работа практическая 1

@ArturNurtdinov ArturNurtdinov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хорошая работа, круто, что ты поработала с форматом и даже с коллекцией ArrayList

Comment thread src/main/java/Check.java
Comment on lines +4 to +15
public static boolean isNumeric(String str)
{
try
{
Integer.parseInt(str);
return true;
}
catch(NumberFormatException e)
{
return false;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если проверять так, то получается, что тебе приходится каждый раз по 2 раза вызывать функцию parseInt - сначала для проверки, а второй раз чтобы получить число после проверки. Можно обойтись одним вызовом, а у класса Scanner есть функции hasNextInt и hasNextFloat, которые помогут избежать лишних вызовов парсинга

Comment thread src/main/java/Check.java
Comment on lines +41 to +43
if(isNumeric(enter))
{
int countPeople = Integer.parseInt(enter);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вот тут получается два вызова Integer.parseInt, один в вызове функции isNumeric, второй - при присовении значения переменной countPeople. Можно здесь обойтись одним вызовом

Comment thread src/main/java/Check.java
else
{
System.out.println("Ошибка, введите числовое значение");
enter = enter().replace(',','.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Много где повторяется enter().replace(',','.');, это можно вынести в отдельную функцию

Comment thread src/main/java/Check.java
Comment on lines +95 to +98
String[] a = String.valueOf(result).split("[.]");
int integralPart = Integer.parseInt(a[0]);
int endOne = integralPart%10;
int endTwo = integralPart%100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Чтобы получить последние две цифры числа не обязательно нужно работать со строкой и парсить заново. Можно чисто операциями деления добиться двух последних цифр числа, например:
последнюю цифру можно получить, взяв остаток от деления на 10
последние 2 цифры - остаток от деления на 100

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.

2 participants