CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Jodhpur -> Rajasthan -> INDIA
    Posts
    453

    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
    Leave Your Mark Wherever You Go
    http://www.danasoft.com/sig/d0153030Sig.jpg

  2. #2
    Join Date
    Apr 2003
    Location
    Los Angeles area
    Posts
    776

    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."

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  4. #4
    Join Date
    Dec 2004
    Posts
    5

    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
  •  





Click Here to Expand Forum to Full Width

Featured