switch---case中的中断和直落

用了那么久switch-case到现在才知道有直落这么回事,看下面例子:

  public static void main(String[] args){ 
      int i = 3; 
    switch(i){ 
        case 3: System.out.println("第一个CASE"); //这里没有用break中断,所以满足条件后就直落下个CASE
        case 2: System.out.println("第二个CASE"); break;//这里使用了break中断,所以没有执行下个CASE块 
        case 4: System.out.println("第三个CASE"); break; 
    } 
  }

输出结果:

第一个CASE

第二个CASE

posted on 2011-12-27 08:46  东方泛起鱼肚白  阅读(536)  评论(0编辑  收藏  举报

导航