How can i take only integer input from keyboard and if input is invalid how do i ask user agaian
        Posted  
        
            by fari
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by fari
        
        
        
        Published on 2010-04-11T04:31:32Z
        Indexed on 
            2010/04/11
            4:33 UTC
        
        
        Read the original article
        Hit count: 407
        
java
|input-validation
This is what i have written so far but when exception is raised it does not again ask teh user for input.
do{
System.out.println("Enter the number of stones to play with: ");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
     String temp=br.readLine();
    }while (key<0 && key>9);
          if(key<0 || key>10)
        throw new InvalidStartingStonesException(key);
                 player1=new KeyBoardPlayer();
         player2 = new KeyBoardPlayer(); 
         this.player1=player1;
         this.player2=player2;
         state=new KalaGameState(key);
    }
     catch(NumberFormatException nFE) {
             System.out.println("Not an Integer");}
    catch(IOException  e)
{
            System.out.println(e);
        }
© Stack Overflow or respective owner