Skip to content

Проектная работа - #1

Open
aNikeevaAlina wants to merge 3 commits into
mainfrom
dev
Open

aNikeevaAlina wants to merge 3 commits into
mainfrom
dev

Conversation

@aNikeevaAlina

Copy link
Copy Markdown
Owner

Консольное приложение №1

Comment thread src/main/java/Guests.java
System.out.println("На скольких человек необходимо рзделить счет?");
try {
countGuest = scanner.nextInt();
} catch (InputMismatchException er) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Удобнее вместо отлавливания ошибки воспользоваться готовым методом scanner.hasNextInt()


String strPriceProduct = scanner.next();
try {
product.price = Double.parseDouble(strPriceProduct);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

У Scanner есть удобный метод hasNextDouble, можно сразу узнать без дополнительных проверок возможно ли интерпретировать строку как double https://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#hasNextDouble%28%29

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