Java 如何确保用户正在输入特定字符串?

Java 如何确保用户正在输入特定字符串?,java,string,encryption,equality,negation,Java,String,Encryption,Equality,Negation,我试图询问用户是否要加密或解密消息,我知道我需要使用userInput.equals(“encrypt”),但我想使用while循环!= while(userInput.!equals("encrypt") || userInput.!equals("decrypt")){ System.out.println("Please try again. Check spelling, and that you typed either 'encrypt' or 'decryp

我试图询问用户是否要加密或解密消息,我知道我需要使用
userInput.equals(“encrypt”)
,但我想使用while循环!=

    while(userInput.!equals("encrypt") || userInput.!equals("decrypt")){
        System.out.println("Please try again. Check spelling, and that you typed either 'encrypt' or 'decrypt'.);
        userInput = scan.nextLine().toLowerCase();
    }

我不知道用户输入的语法。!相等(“x”)。(显然,我所说的不对)。

只需将
while loop
条件更改为:

while(!userInput.equals("encrypt") && !userInput.equals("decrypt"))
此外,如果要忽略大小写:

while(!userInput.equalsIgnoreCase("encrypt") && !userInput.equalsIgnoreCase("decrypt"))

在(!userInput.equal(“encrypt”)| | |!userInput.equal(“decrypt”)时,将感叹号放在方法调用
的前面,这样输出就不会有问题了,谢谢。它起作用了。我再等几分钟就不能接受答复了。它总是不等于“加密”或不等于“解密”。这不应该是一个
&&
?但它需要是
&&
,而不是
|