Skip to content

Conversation

@aNikeevaAlina
Copy link
Owner

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

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

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);

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.

3 participants