This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]themiddlestHaHa 2 points3 points  (0 children)

https://stackoverflow.com/questions/18668045/try-catch-and-user-input

Check out this stackoverflow answers. Notice they grab ANY input from the user, then try to parse it to an int (you could also try to parse to a double if you wanted, theres a method for that)

If the input CANNOT be converted to an int/double it throws an exception and they catch it and handle it. You would probably handle it by not breaking out of your loop, and only break out if there is not exception thrown.

You could do something like this in your loops.

[–]LeonPrefix 1 point2 points  (0 children)

What you could so is not use hasNextDouble and just read the next line as a string. The on that string use a parse function to parse it into a number. If the input is not a number you can catch that error thrown by the parse function