- public class SwitchCase {
- public static void main(String[] args) {
- System.out.println(switchFun(4)); //运行结果:8
- }
-
- public static int switchFun(int x){
- int j = 1;
- switch (x) {
- case 1:
- j++;
- case 2:
- j++;
- case 3:
- j++;
- case 4: //输入x=4,从此处开始执行,一直到末尾,default里面的内容也会执行
- j++; //由于j++是单独一行,等效于j = j + 1,不存在先使用后+1的情况
- case 5:
- j++;
- default:
- j++;
- }
- return x+j;
- }
- }