Results 1 to 8 of 8
  1. #1
    thiagohe is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default Help with Console

    Hello, using the console I want read two or more variables in the same line.
    Exemple: "John 9" or "Michelle 8".
    After assign 'John' to String variable and '9' to int variable. without strings treatment

    can anybody help me? thanks

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default

    Look into String.split().
    Get in the habit of using standard Java naming conventions!

  3. #3
    thiagohe is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    no, It doesn't help

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    thiagohe is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    I didn't use split. My problem is at reading.

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default

    I thought you were already reading "John 9" or "Michelle 8". Use Console.readLine() to read those strings. Then use String.split() on them.
    Get in the habit of using standard Java naming conventions!

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Yes, I understood what you want to do. Reading something like "John 9", you need to separate into "John" and "9". String (Java Platform SE 6) Does the same. Have you read it?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    Another approach is to use the Scanner class. It has methods that will read a word from the console and it will read a word and convert it to an int. The two can be typed on the same line before pressing Enter

Similar Threads

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 09:32 PM
  2. No errors but, nothing in console ..?
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 07-04-2010, 11:58 PM
  3. Java Console
    By stiwi in forum Java Software
    Replies: 4
    Last Post: 05-19-2010, 02:53 PM
  4. implementing a console
    By bilbodeb in forum Threads and Synchronization
    Replies: 2
    Last Post: 03-26-2009, 07:09 AM
  5. how to take input from console in jsp
    By veena in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 04:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •