Campbell Ritchie wrote:Welcome to JavaRanch
Rob Spoor points out it is completely possible to avoid the InputMismatchException like this, or something rather similar:
Correct. The input.next() inside the method is used to consume the non-int. The guard is slightly wrong though; it should also check for input.hasNext:
I think I forgot the hasNext() before in the loop, but that could cause an exception with the input.next() call if the stream is closed.