fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. Scanner input = new Scanner(System.in);
  14. boolean tryAgain = true;
  15. do {
  16. try {
  17. System.out.println("Please enter an integer between 9 and 99: ");
  18.  
  19. int inInt = input.nextInt();
  20.  
  21. if (inInt >= 9 && inInt <= 99){
  22. System.out.println("Thank you. Initialization completed.");
  23. tryAgain = false;
  24. }
  25. else if (inInt < 9 || inInt > 99){
  26. throw new NumberFormatException("Integer is out of range.");
  27. }
  28. }
  29. catch (NumberFormatException e1) { // Range check
  30. System.out.println("* The number you entered is not between 9 and 99. Try again.");
  31. System.out.println();
  32. input.nextLine();
  33. }
  34. catch (InputMismatchException e2) { // Something other than a number
  35. System.out.println("* You did not enter an integer. Try again.");
  36. System.out.println();
  37. input.nextLine();
  38. }
  39. } while(tryAgain);
  40. }
  41. }
Runtime error #stdin #stdout #stderr 0.06s 2184192KB
stdin
22.1
stdout
Please enter an integer between 9 and 99: 
* You did not enter an integer.  Try again.

Please enter an integer between 9 and 99: 
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Ideone.main(Main.java:19)