Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Having trouble with strings

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Having trouble with strings

    Ok here is what I'm using to get user input to get a whole sentence including the spaces between the words:

    sentence = input.next();

    However instead of storing the entire sentence it only stores the first word.

    How can I store the whole sentence in a string?
    Last edited by Reaperkid77; October 20th, 2009 at 07:33 PM. Reason: Had to add ; at end of example code


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Having trouble with strings

    I take it the input variable is a Scanner ?

    input.useDelimiter("\n");

    That might work

    // Json

  3. The Following User Says Thank You to Json For This Useful Post:

    Reaperkid77 (October 20th, 2009)

  4. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Having trouble with strings

    or input.nextLine()

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    Reaperkid77 (October 20th, 2009)

  6. #4
    Junior Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble with strings

    Thanks for to feed back, input is a scanner object and the .nextLine() method worked

Similar Threads

  1. Having trouble redirecting nodes
    By KingLane in forum Collections and Generics
    Replies: 6
    Last Post: October 19th, 2009, 07:46 PM
  2. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 08:02 PM
  3. Trouble in downloading java
    By captjade in forum Java Theory & Questions
    Replies: 6
    Last Post: March 3rd, 2009, 04:16 PM
  4. Replies: 2
    Last Post: June 19th, 2008, 04:58 AM

Tags for this Thread