Hey there,
still working on my first project, a simple dice game, as I mentioned already in another thread. So far everything worked fine the way I wanted it to work, but now I got stuck with an infinite loop I can't figure out.
In a game initializing class ("NewGame.java") I have this method:
Code:public static int newOpponents(String playersName) {
Scanner input = new Scanner(System.in);
int numberOfOpponents = 0;
do {
System.out.println();
System.out.print("Hello " + playersName + ". How many people do you want to play with (max. 5)? ");
try {
numberOfOpponents = input.nextInt();
} catch (InputMismatchException wrongInput) {
numberOfOpponents = 999;
}
} while ((numberOfOpponents < 1) || (numberOfOpponents > 5));
return numberOfOpponents;
}
From main(), I call it via
Code:numberOfOpponents = NewGame.newOpponents(player1.getPlayersName());
It works fine as long as I type in numbers. But if I type in any letter, I get caught in an infinite loop that just executes the
Code:System.out.print("Hello " + playersName + ". How many people do you want to play with (max. 5)? ");
statement. It doesn't seem to reach the try/catch anymore. Any ideas why that is?

