I am programming a monopoly type game on java and am having a little trouble setting up the validation for the player select function. The user will have to chose between 2-4 players.
Below is my attempt at doing this utilizing an if else statement and a while loop.
I can't figure out the right way of implementing this and would appreciate any advice.
int numberPlayers = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter Number of players (2-4)");
if (scanner.nextInt() >= 2 && scanner.nextInt() <= 4) {
numberPlayers = scanner.nextInt();
System.out.println(numberPlayers + " players selected");
} else {
while (scanner.nextInt() < 2 || scanner.nextInt() > 4) {
System.out.println("Not a valid choice. Please enter Number of players (2-4)");
}
}