0

I'm trying to ask a user whether they want to encrypt or decrypt a message, and I know that I need to use userInput.equals("encrypt"), but i want to use a while loop with !=.

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

and I dont know the syntax for the userInput.!equal("x"). (Obviously, what I put is not right).

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • put the exclamation mark in front of the method call `while(!userInput.equal("encrypt") || !userInput.equal("decrypt"))`, so the output gets inverted – Japu_D_Cret Mar 25 '17 at 17:31
  • Yeah, thanks. It works. I can't accept an answer for another couple minutes tho –  Mar 25 '17 at 17:39
  • 2
    Wait. It will ALWAYS either not equal "encrypt" or not equal "decrypt". Shouldn't that be a `&&`? – D M Mar 25 '17 at 17:42

1 Answers1

1

Simply change the while loop condition to this:

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

also, if you want to ignore case:

while(!userInput.equalsIgnoreCase("encrypt") && !userInput.equalsIgnoreCase("decrypt"))
Ousmane D.
  • 54,915
  • 8
  • 91
  • 126