Advertisement
Nickpips

Untitled

Nov 28th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public static int getInt(int a, int b) {
  2. int input = getInt();
  3. while( input < a || input > b ) {
  4. System.out.println("You must pick a number in-between " + a + " and " + b + "!");
  5. input = getInt();
  6. }
  7. return input;
  8. }
  9.  
  10. public static int getInt() {
  11. int output = 0;
  12. while( true ) {
  13. try {
  14. output = scan.nextInt();
  15. } catch( InputMismatchException e ) {
  16. System.out.printf("Please input an integer.\n");
  17. scan.nextLine();
  18. continue;
  19. } catch( Exception e ) {
  20. System.out.println("Exception: " + e);
  21. return -1;
  22. }
  23. break;
  24. }
  25. scan.nextLine();
  26. return output;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement