I'm trying to prompt the user to give me one of three strings: "Amsterdam," "Lexington," and "Madison." If the user doesn't enter one of those strings, they should be repeatedly prompted until they do so.
When I type a string that's supposed to be acceptable, like "Lexington," I still receive "Please enter a valid city."
Can anyone tell me how the While loop is being run even when I'm negating the conditionals in it?
public String readCity() {
String x = keyboard.next();
while (!x.equals("Amsterdam") || !x.equals("Lexington") || !x.equals("Madison")) {
System.out.println("Please enter a valid city.");
x = keyboard.next();
}
return x;
}
if (!cityArray.contains(x)). This would also shorten your if-statement, especially if more cities are added laterxcontains "Amsterdam", then what does!x.equals("Amsterdam")return? What does!x.equals("Lexington")return? What does!x.equals("Madison")return? What happens when you||those things together?