解决方案
此示例显示如何使用 Switch 语句检查选择了哪个枚举成员。
enum Car {
lamborghini,tata,audi,fiat,honda
}
public class Main {
public static void main(String args[]){
Car c;
c = Car.tata;
switch(c) {
case lamborghini:
System.out.println("You choose lamborghini!");
break;
case tata:
System.out.println("You choose tata!");
break;
case audi:
System.out.println("You choose audi!");
break;
case fiat:
System.out.println("You choose fiat!");
break;
case honda:
System.out.println("You choose honda!");
break;
default:
System.out.println("I don't know your car.");
break;
}
}
}