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
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.
Re: How to get user input as integer in console application?
Quote:
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
Re: How to get user input as integer in console application?