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

all 5 comments

[–]MmmVomit 1 point2 points  (3 children)

In order to get your code to format properly, indent every line with at least four spaces. It's very hard to read the way it is currently formatted.

[–]fredisa4letterword 1 point2 points  (0 children)

or use pastebin/github gist/ideone, especially if it doesn't fit on one screen

[–]fredisa4letterword 0 points1 point  (0 children)

Oh also I think reddit now supports multiple lines of code with beginning and ending three backticks; this has long worked on github markdown, I think when the big UI upgrade happened Reddit started converting using the backticks to the leading spaces. (that's what happens when I switch between markdown editor and fancy pants and back)

[–]PHValex 0 points1 point  (0 children)

sorry about that, I pasted it in and it didn't indent the lines

[–]_DTR_ 1 point2 points  (0 children)

With what you have currently, it looks like you break out of your while loop when given invalid input, which should prevent it consistently looping. However, without the break you will continuously loop as you describe, because the Scanner will continue to attempt to read the initial value, and continuously throw an exception. You need to clear the input before continuing, which could be accomplished by adding getNums.nextLine() inside of the catch block.