Results 1 to 8 of 8
  1. #1
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Lightbulb Get Help with Scanner for String with space in JAVA

    May I know how do I use Scanner with spaces in JAVA? Thanks.

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Please define your problem in greater detail. What is your text? What have you tried? What problems are you currently having? About all I can say based on your somewhat general question is here's the tutorial: How to use the Scanner

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Do you want to read spaces or skip spaces?

  4. #4
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    I want to read spaces. I got it now. Thanks a lot for your help, Norm:)

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Can you post your solution so others will know how to do it?

  6. #6
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    Yes, sure. I will try to post my solution next time. THanks a lot for your advices :)

  7. #7
    hanthuy is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default

    Scanner input = new Scanner(System.in);
    String str1 = input.next();
    String str2 = input.nextLine();
    If you use next() --> Take the first word of String you enterd.
    Ex: Hello my friend --> str1 = "Hello"
    It better if you use nextLine() --> str2 = "Hello my friend"
    Last edited by hanthuy; 09-14-2010 at 05:07 PM. Reason: better

  8. #8
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

Similar Threads

  1. Can i use Java Scanner with String?
    By guitar-maniac in forum New To Java
    Replies: 7
    Last Post: 09-15-2014, 08:59 AM
  2. how to repalce space with %20 in a string
    By Basit781 in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-13-2012, 09:08 PM
  3. Java split string, the first char is a space
    By new_cyber in forum New To Java
    Replies: 8
    Last Post: 12-31-2009, 02:27 AM
  4. Replies: 0
    Last Post: 11-17-2009, 02:58 PM
  5. Replies: 0
    Last Post: 11-20-2007, 05:59 PM

Posting Permissions

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