比如我要判断一个某个月是哪个季节,可以这样写:
switch (month) {
case 1:
case 2:
case 12:
System.out.println(month + “月是冬季”);
break;
case 3:
case 4:
case 5:
System.out.println(month + “月是春季”);
break;
case 6:
case 7:
case 8:
System.out.println(month + “月是夏季”);
break;
case 9:
case 10:
case 11:
System.out.println(month + “月是秋季”);
break;
default:
break;
}
小严成长日记之switch的便捷实用---节省代码量!
最新推荐文章于 2023-01-22 21:40:25 发布