I'm trying to finish some code for my homework. But this line of code doesn't seem to work correctly for me. I want the user to only input the following string: freshman, sophomore, junior or senior. Any other input is invalid.
Don't know what else to try, I'm fairly new to java.
while (true) {
System.out.println("Enter undergraduate level: ");
lvl = inReader.nextLine();
if (lvl != "freshman" || lvl != "sophomore" || lvl != "junior" || lvl != "senior") {
System.out.println("Please enter valid level.");
} else {
break;
}
}
I expected the input to only take freshman, sophomore, junior, and senior as in input, but it takes no inputs and only displays "Please enter valid level."