我正在尝试询问用户是否要加密或解密消息,我知道我需要使用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();
}
我不知道userInput.!equal("x")
的语法。 (显然,我所说的不对)。
答案 0 :(得分:1)
只需将while loop
条件更改为:
while(!userInput.equals("encrypt") && !userInput.equals("decrypt"))
另外,如果你想忽略大小写:
while(!userInput.equalsIgnoreCase("encrypt") && !userInput.equalsIgnoreCase("decrypt"))