View Single Post
  #2 (permalink)  
Old 12-16-2007, 11:37 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
You can use some if-else statements to test/qualify the iuput.
For example,
Code:
BufferedReader reader = ... int n = -1; do { System.out.println("enter 1 or 2"); String line = reader.readLine(); if(line != null && line.length() > 0) { // User entered something so we may have something to parse. // You may want to check that "line" contains parsable digits // with something like Character.isDigit. // Or, you could use a try/catch for NumberFormatException. n = Integer.parseInt(line); } } while(n != 1 && n != 2);
Reply With Quote