-
March 21st, 2005, 06:08 PM
#1
How to get user input as integer in console application?
Hello
I am developing a console application in which i need to take user input as integer value. How to get this?
I tried
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
Well but but rd does have only readLine method, and i need to read integer?
Sandeep
-
March 21st, 2005, 07:21 PM
#2
Re: How to get user input as integer in console application?
Read in all user input as a string first. You can then send it to Integer.parseInt to get an int back.
You should probably look over the documentation for the classes contained in the java.lang, java.util, and java.io packages. Knowing what is available beforehand will save you alot of time down the road.
"The Chicken and Rice MRE is not a personal lubricant."
-
March 26th, 2005, 05:49 AM
#3
Re: How to get user input as integer in console application?
Originally Posted by d0153030
Hello
I am developing a console application in which i need to take user input as integer value. How to get this?
I tried
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
Well but but rd does have only readLine method, and i need to read integer?
Sandeep
no, rd has all the methods of the other readers:
http://java.sun.com/j2se/1.4.2/docs/...redReader.html
but i suggest you follow joes advice, read in the string with readLine() then convert it to an int
-
March 28th, 2005, 01:53 PM
#4
Re: How to get user input as integer in console application?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|