我有以下代码:
playAgain = userInput.next().toUpperCase().toCharArray();
while (playAgain[0] != 'Y' || playAgain[0] != 'N') {
System.out.println("Do you want to play again? Press 'YES' for yes or 'NO' for no");
playAgain = userInput.next().toUpperCase().toCharArray();
}
有人可以向我解释为什么会导致无限循环吗?
如果我只使用:
playAgain = userInput.next().toUpperCase().toCharArray();
while (playAgain[0] != 'Y') {
System.out.println("Do you want to play again? Press 'YES' for yes or 'NO' for no");
playAgain = userInput.next().toUpperCase().toCharArray();
}
它会正常工作,但如果我使用||运算符,它会导致无限循环..