Guest User

Untitled

a guest
Dec 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. boolean check = true;
  2.  
  3. while(check) {
  4.  
  5. try {
  6. check = false; //ставим false, что бы не вводить больше данные
  7. ...//Ввод данных
  8. } catch(InputMismatchExeption ex) {
  9. ...//Ваши действия
  10. check = true; //если вышло исключение, ставим обратно true, что бы опять вводить данные
  11. }
  12. }
  13.  
  14. int number;
  15. do {
  16. System.out.println("Please enter a positive number!");
  17. while (!sc.hasNextInt()) {
  18. System.out.println("That not a number!");
  19. sc.next(); // this is important!
  20. }
  21. number = sc.nextInt();
  22. } while (number <= 0);
  23. System.out.println("Thank you! Got " + number);
  24.  
  25. Thread.sleep(20);
Add Comment
Please, Sign In to add comment