What am I doing wrong? I need the game to repeat until a user enters N or n. Instead, it just keeps going and going and going......
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int noOfPlayers;
String playAgain;
Scanner game = new Scanner(System.in);
do {
System.out.print("How many players in the game :");
noOfPlayers = game.nextInt();
if(noOfPlayers > 5) {
System.out.println("Only 5 or less players can play.");
System.out.println("How many players in the game (1-5) :");
noOfPlayers = game.nextInt();
}
Game g=new Game(noOfPlayers);
g.readPlayernames();
g.playGame();
System.out.println("Would you like to play again? Y or N.");
playAgain = game.next();
}
while(playAgain != "Y" || playAgain !="y");
}
}