大家帮我看下这段代码
int i = 1, j = -1;
switch (i) {
case 0:
j = 1;
case 1:
j = 1;
case 2:
j = 2;
default:
j = 0;
}
System.out.println("j=" + j);
What is the result?
为什么结果老是 0 呢?大家帮忙解释下,谢谢
[解决办法]
int i = 1, j = -1;
switch (i) {
case 0:
j = 1;
break;
case 1:
j = 1;
break;
case 2:
j = 2;
break;
default:
j = 0;
}
System.out.println("j=" + j);
按以上的试试!