public class EnumDemo
{
private enum Season
{
spring,summer,fall,winter
}
private static void doIt(Season s)
{
switch (s)
{
case spring:
System.out.println("value is " + Season.spring);
case summer:
System.out.println("value is " + Season.summer);
break;
case fall:
System.out.println("value is " + Season.fall);
case winter:
System.out.println("value is " + Season.winter);
break;
default:
System.out.println("default");
}
}
public static void main(String[] args)
{
for(Season s: Season.values())
{
System.out.println(s);
}
doIt(Season.fall);
}
}
以上例子中:
for(Season s: Season.values())
{
System.out.println(s);
}的输出结果是:spring
summer
fall
winter
doIt(Season.fall);的输出结果是:fall
winter
switch(x) :从指定的case-x处开始执行 遇到break结束。