-
reading a sentence
i used .next() in my program and when i type a sentence with a spacing it goes to the next line with another prompt sentence anyone knows why?
i will upload screenshots of the problem i have.
sentence without spacing:
http://i27.photobucket.com/albums/c1...va/correct.jpg
sentence with spacing:
http://i27.photobucket.com/albums/c1...a/errorrun.jpg
-
Re: reading a sentence
I think this is because you are using .next() and that reads the first word only. Try .nextLine()
-
Re: reading a sentence
i figured it out when i put this static Scanner myScanner = new Scanner(System.in).useDelimiter("\r\n"); it works any idea what the .useDelimiter does?
-
Re: reading a sentence
A delimiter is a character that identifies the beginning or the end of a character String.
Delimiter - Wikipedia, the free encyclopedia
If for example you have a comma in your sentance, you can set the delimiter to comma and split the sentance at that point.
I would still recommend using myScanner.nextLine(); though.
-
Re: reading a sentence
i tried using nextLine but it also skips to another line