i am using scanner class, i faced problem when i tried to get a string with space. How can i modify my code to solve the problem. Here is my code:

import java.util.Scanner;

class abc
{
public void main(String[] args)
{
Scanner abc = new Scanner(System.in);
System.out.print("Name: ");
String nameStr = abc.next();
}
}

If this is what you want to enter: John Smith, then try inserting
"John Smith"
By the way you don't say what exactly is you problem and what you are trying, to do. Post your inputs, what it is stored in the variable and what you wanted to be stored

Scanner.next() returns up to the next delimeter, which is a space by default

what do you expect it to do?

if you want to read the rest of the line, you can use the "nextLine()" method

i think this should solved the problem. Sorry for confusing because i am still new in java.

This question has already been answered. Start a new discussion instead.