case标签
case标签可以是:
常量表达式:char,byte,short,int
枚举常量
字符串字面量
当在switch语句中使用枚举常量时,不用在每个标签中指明枚举名,可以由switch的表达式值确定。
代码实现
size.java
package hello;
public enum size {
small,medium,large,xlarge;
}
clothe.java
package hello;
public class clothe {
public static void main(String[] args){
size sz=size.large;
switch (sz){
case small:
System.out.println("small");
break;
case medium:
System.out.println("medium");
break;
case large:
System.out.println("large");
break;
default:
System.out.println("xlarge");
}
}
}
运行结果: