My program has an endless loop, when I use try and catch block in a while loop.
import java.util.*;
class Try
{
public
Scanning an int
does not consume the newline charackter (pressing enter). Therefor it reads the newline charackter every time and throws an InputMismatchException.
You can consume it by simply calling next()
or nextLine()
after your make your input.
Note: next() does only work on unix since it reads only one byte and Windows ends a line with two charackters (\r\n).