CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013
    Posts
    4

    Question How To Enter Name with Whitespaces in a String Variable

    Hi Team,

    I am wondering how to enter a string with White Space and Store it in a String variable.

    For example : I have created a string named "name".

    String name;

    I want to Store "Michael Jackson" in the String "name". I couldn't do it. My program Just accepts Michael and not Jackson.

    here is my code ;

    import java.util.Scanner;

    public class Stringtwo

    {

    public static void main(String[] args)

    {

    String name;

    Scanner scannedInfo=new Scanner(System.in);

    name=scannedInfo.next();

    System.out.println(name);

    }

    }

  2. #2
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: How To Enter Name with Whitespaces in a String Variable

    1. Please use code tags! http://forums.codeguru.com/misc.php?do=bbcode#code
    2. Scanner's next() method reads the next token delimited by default delimiter which is space. To read the whole line use nextLine() method.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

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
  •  





Click Here to Expand Forum to Full Width

Featured