All pastes #2106575 Raw Edit

Anonymous

public text v1 · immutable
#2106575 ·published 2012-01-26 19:37 UTC
rendered paste body
//If user's input is a String or a number not within specified range, the program asks the user to reenter
            //This method allows the user to enter text even though an integer is expected
            public static int intInput(int min, int max)
            {
               Scanner sc = new Scanner(System.in);
               String stringChoice;
               int intChoice = 0;
               do{
                    stringChoice = sc.nextLine(); 
                    try 
                    {
                        intChoice = Integer.parseInt(stringChoice);
                    } 
                    catch (NumberFormatException ex)  
                    { }    
                    
                    if ((intChoice < min) || (intChoice > max))
                        System.out.print ("**Invalid input** Re-enter choice: "); 
                        
                  }while ((intChoice < min) || (intChoice > max)); 
                  
               return intChoice;        
            }