The part of the Java program that I am doing is asking the user for his home country. The other part uses the switch statement, and I get an error. Error: The operator || is undefined for the argument type(s) java.lang.String, java.lang.String. Here is the method where the problem occurs:
public static String getCountryMessage(String countryName) {
switch (countryName) {
case "USA":
return "Hello, ";
case "England" || "UK":
return "Hallo, ";
case "Spain":
return "Hola, ";
case "France":
return "Bonjour, ";
case "Germany":
return "Guten tag, ";
default:
return "Hello, ";
}
}
How to use && and || in a java switch statement?
source
share