How do you scan a string with spaces?
How do you input a string that has spaces in it?
For example in this program
if you type in, say, 'hello world', it will only print 'hello'. Why is this? Is there a way to get input for a string with spaces?
System.out.print("Type something: ");
Scanner scan = new Scanner(System.in);
String x = scan.next();
Re: How do you scan a string with spaces?
Have you looked at the API for Scanner? There's a method that
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end.