Results 1 to 3 of 3
-
Reading int values using BufferedReader
The static method below reads only int values using BufferedReader (stdin) and throws Exception if int is not read.
Java 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 ()
- 01-24-2008, 07:42 PM #2
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
Another way is using the Scanner class.
int value = new Scanner(System.in).nextInt();
- 01-24-2008, 08:26 PM #3
Welcome to the Java Forums Christian!
As you are probably aware, there are typically more than one way to perform a task in Java. :)
Just wanted to welcome you to our community. See you around!
-CaptVote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
Reading a file from Applet (BufferedReader)
By Java Tip in forum Java TipReplies: 1Last Post: 06-22-2008, 11:51 PM -
Reading Float values from a file
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 10:20 AM -
Reading file contents (BufferedReader)
By Java Tip in forum Java TipReplies: 0Last Post: 02-07-2008, 10:00 AM -
Reading text from a URL using BufferedReader
By Java Tip in forum Java TipReplies: 0Last Post: 12-26-2007, 11:17 AM
Bookmarks