Skip to content

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

Open
RomanKalin27 wants to merge 2 commits into
Yandex-Practicum:masterfrom
RomanKalin27:master
Open

RomanKalin27 wants to merge 2 commits into
Yandex-Practicum:masterfrom
RomanKalin27:master

Conversation

@RomanKalin27

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/main/java/calc.java
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
Copy Markdown

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?

Comment thread src/main/java/calc.java
}
}
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
Copy Markdown

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

Comment thread src/main/java/calc.java
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
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants