View Single Post
  #1 (permalink)  
Old 01-24-2008, 05:22 PM
Java Tip Java Tip is offline
Moderator
 
Join Date: Nov 2007
Posts: 1,659
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Reading int values using BufferedReader
The static method below reads only int values using BufferedReader (stdin) and throws Exception if int is not read.

Code:
public static int readInt () { while (true) { try{ String line = stdin.readLine(); int value = Integer.parseInt(line); return value; } catch(java.lang.NumberFormatException e){ ; } catch(IOException e){ ; } } } // end readInt ()
Reply With Quote
Sponsored Links