switch语句注意
switch语句
自JDK1.7开始switch语句中除了可以case int类型还可以case String类型;
break不是必须,如果不写会发生case穿透。(case可以合并利用的就是这个原理)
格式:
switch(int或者String类型的数据){
case int或者String类型的数据:
语句;
break;
case int或者String类型的数据:
语句;
break;
default : //default不是必须写的
}
switch语句
自JDK1.7开始switch语句中除了可以case int类型还可以case String类型;
break不是必须,如果不写会发生case穿透。(case可以合并利用的就是这个原理)
格式:
switch(int或者String类型的数据){
case int或者String类型的数据:
语句;
break;
case int或者String类型的数据:
语句;
break;
default : //default不是必须写的
}