Results 1 to 2 of 2
- 11-10-2012, 05:52 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
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?Java Code:System.out.print("Type something: "); Scanner scan = new Scanner(System.in); String x = scan.next(); System.out.println(x);
Thanks!
- 11-10-2012, 06:06 AM #2
Re: How do you scan a string with spaces?
Have you looked at the API for Scanner? There's a method that
dbAdvances 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.Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Removing spaces in String ArrayList
By dougie1809 in forum New To JavaReplies: 6Last Post: 03-13-2012, 09:25 PM -
how to use Scanner to scan a String
By RichersooN in forum New To JavaReplies: 1Last Post: 09-23-2011, 05:14 AM -
how to copy a string and replace all the spaces with tabs
By stevisto in forum New To JavaReplies: 1Last Post: 09-15-2011, 01:51 PM -
How to display a String that contains more than one white spaces
By thachun in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 09-27-2009, 09:16 AM -
Checking if string contains only tabs/spaces/newlines/carriage returns
By Singing Boyo in forum New To JavaReplies: 3Last Post: 08-20-2009, 03:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks