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

Comments

Калькулятор. Дубль 2.#76

Open
RomanKalin27 wants to merge 2 commits intoYandex-Practicum:master from
RomanKalin27:master
Open

Калькулятор. Дубль 2. #76
RomanKalin27 wants to merge 2 commits intoYandex-Practicum:master from
RomanKalin27:master

Conversation

@RomanKalin27
Copy link

@RomanKalin27 RomanKalin27 commented Oct 18, 2022

Программа больше не падает при некорректном вводе числа человек.
Окончание теперь выводиться правильно.

System.out.println("Привет Мир");
Scanner scan = new Scanner(System.in);
System.out.println("На сколько человек вы хотели бы разделить чек?");
try {
Copy link

@MagicUnderHood MagicUnderHood Oct 19, 2022

Choose a reason for hiding this comment

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

Можно try-catch разместить внутри бесконечного цикла while, тогда при вводе строки пользователю будет позволено снова ввести число, без перезапуска программы (как сделано с числами меньше 1)

System.out.println("На сколько человек вы хотели бы разделить чек?");
try {
int numPeople = scan.nextInt();
while (1 < 4) {
Copy link

@MagicUnderHood MagicUnderHood Oct 19, 2022

Choose a reason for hiding this comment

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

Можно вместо 1 < 4 писать просто true

Scanner scan2 = new Scanner(System.in);
Scanner scan3 = new Scanner(System.in);
Scanner scan4 = new Scanner(System.in);
for (String i = "Добавленные товары:"; 1 != 0; i = i) {
Copy link

@MagicUnderHood MagicUnderHood Oct 19, 2022

Choose a reason for hiding this comment

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

1 != 0 можно заменить на true, а i = i убрать. Может, здесь for можно заменить на цикл while?

}
}
public static String ending(double j){
if(Math.floor(j) % 100 == 11 ^ Math.floor(j) % 100 == 12 ^ Math.floor(j) % 100 == 13 ^ Math.floor(j) % 100 == 14){
Copy link

@MagicUnderHood MagicUnderHood Oct 19, 2022

Choose a reason for hiding this comment

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

Math.floor(j) % 100 повторяется. можно посчитать один раз, записать в переменную и использовать её
Вместо ^ чаще используют написание ||
Можно условие заменить на Math.floor(j) % 100 >= 11 && Math.floor(j) % 100 <= 14

public static String ending(double j){
if(Math.floor(j) % 100 == 11 ^ Math.floor(j) % 100 == 12 ^ Math.floor(j) % 100 == 13 ^ Math.floor(j) % 100 == 14){
String stringe = " рублей";
return stringe;
Copy link

@MagicUnderHood MagicUnderHood Oct 19, 2022

Choose a reason for hiding this comment

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

Можно убрать переменную, написав просто return " рублей";, и ниже тоже

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

Reviewers

1 more reviewer

@MagicUnderHood MagicUnderHood MagicUnderHood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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