无论我选择“ Y”还是“ N”,do while循环都不会终止。
我尝试对Y和N使用各种版本的==或!=
do {
num = (int)((Math.random() * max) + 1);
System.out.println("A new secret number has been chosen.");
do {
System.out.println("Enter a guess: ");
guess = scan.nextInt();
if (guess < num) {
System.out.print("Too low. Try again.");
} else if (guess > num) {
System.out.print("Too high. Try again.");
}
tries++;
}while(guess != num);
System.out.println("You won in " + tries + " guesses.");
System.out.println("Play Again? (Y/N)");
game = scan.next();
tries = 0; }while(game != "N");
我希望它在用户键入“ N”时终止程序。