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 re
If you use Java 7 or above I would prefer the following code:
public String readCity() {
while (true) {
String x = keyboard.next();
switch(x) {
case "Amsterdam":
case "Lexington":
case "Madison":
return x;
default:
System.out.println("Please enter a valid city.");
}
}
}