switch中的误区

来源:互联网 发布:银河证券软件下载 编辑:程序博客网 时间:2024/05/18 00:33
switch(g) {case 0:System.out.println(0);g=1;case 1:System.out.println(1);break;default:System.out.println(2);break;}

在等于1的情况下没有写break,导致匹配到0时,同时也会执行1的分支语句