-1

I'm trying to make a user validation for multiple choices using a while loop and If the user doesn't match the choices then the program has to terminate. This is what I got so far

  while(input!="air" || input!="water" || input!="steel"){
        System.exit(0);
    }

Unfortunately, it doesn't work.

I would prefer to do exceptions, but my professor is strictly against using it for this assignment. I really want to grow as a programmer so any advice, tips and tricks are welcomed, thank you all for trying to help me out.

Alexa431
  • 7
  • 5

1 Answers1

-1

Change it as

while(!input.equals("air") && !input.equals("water") && !input.equals("steel")){
    System.exit(0);
}

Or

while(!(input.equals("air") || input.equals("water") || input.equals("steel"))){
    System.exit(0);
}
so-random-dude
  • 15,277
  • 10
  • 68
  • 113