1.与if…else…不同的是,switch…case只能完成等值判断,无法完成判断大小。
2.switch 只支持 int、short、byte、char、枚举、String 类型,不支持 boolean 类型。
基本语法:
switch(变量){
case 值1:
//业务代码
System.out.println("结果1");
break;
case 值2:
//业务代码
System.out.println("结果2");
breka;
default:
//业务代码
System.out.println("结果3");
break;
}