Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean check = true;
- while(check) {
- try {
- check = false; //ставим false, что бы не вводить больше данные
- ...//Ввод данных
- } catch(InputMismatchExeption ex) {
- ...//Ваши действия
- check = true; //если вышло исключение, ставим обратно true, что бы опять вводить данные
- }
- }
- int number;
- do {
- System.out.println("Please enter a positive number!");
- while (!sc.hasNextInt()) {
- System.out.println("That not a number!");
- sc.next(); // this is important!
- }
- number = sc.nextInt();
- } while (number <= 0);
- System.out.println("Thank you! Got " + number);
- Thread.sleep(20);
Add Comment
Please, Sign In to add comment