为什么我的OR运算符不能在这里工作?

时间:2015-01-19 20:20:48

标签: java while-loop operators

我有以下代码:

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();
        }

它会正常工作,但如果我使用||运算符,它会导致无限循环..

0 个答案:

没有答案