What Scanner#next does is to read from where you are until the next whitespace. So you enter
and the Scanner returns
Now that won't work for the simple date format parser. Try nextLine instead of next.
I shall go back to your post and add code tags which will make it look much better as long as you have indented the code. Alwys use the code tags.
james kinyua wrote:
the output is
java.text.ParseException: Unparseable date: ""
The error message is saying that it is trying to parse a blank string. So, this is not an issue of parsing incorrectly. This is an issue of getting the wrong input. Most likely, you type an extra return (or had an extra return from previous input).
Regardless, your best action to resolve this is probably to read again until you get an actual string that you can parse. And even so, what if the user enters an invalid string? Are applications supposed to be breakable by user input?
How on earth can you get an empty String from that Scanner with next(), unless you change its delimiter? You can get an empty String with nextLine() so I was about to ask OP what his book says nextLine() does, then I saw there is no sign of nextLine() being used.
I tried it myself changing next() to nextLine() twice and get a difference in time printed.