枚举类型(enum)在Switch中的使用以及遍历枚举类型(enum)中的内容
public class EnumDemo {
//定义枚举类型
enum Month {
January, February, March, April, May, June, July,August,September,October,November,December
}
public static void main(String[] args) {
Month mon = Month.August;
switch (mon) {
case August:
System.out.println("这是个旅游的季节");
break;
case December:
System.out.println("这是个滑雪的季节");
break;
}
//循环遍历枚举类型Month
for (Month month : Month.values()) {
System.out.println(month + ", 顺序: " + month.ordinal());
}
}
}