I need help with the SIMPLE Y / N Condition for my program. I really don't work the way I want.
Unfortunately, all the other topics that I find are very confusing. I am very new to programming.
I want a Y / N condition that will not work and will not be CASE SENSITIVE. therefore, if Y or y returns to another menu, if n and N just stop the program, and if something else types in it, it will loop until the conditions Y or N. are met.
Here is what I wrote:
String input = ScanString.nextLine();
while (!"Y".equals(input) || !"y".equals(input) || !"N".equals(input) || !"n".equals(input)) {
System.out.println("Please enter Y/N (Not case sensitive): ");
input = ScanString.nextLine();
}
if ("Y".equals(input) || "y".equals(input)) {
meny1();
} else if ("N".equals(input) || "n".equals(input)) {
}
When it starts, no matter what I put in, it will not break the while loop.
source
share