这段程序的输出为什么是 Value is two.
                       Value is three.怎么不是 Value is two.
         Value is 2public class SwitchTest
{
  public static void main(String[] args)
  {
    int j = 2;
    switch ( j )
    {
      case 2:
        System.out.println("Value is two.");
      case 10:
        System.out.println("Value is three.");
        break;
      default:
        System.out.println("Value is " + j);
        break;
    }
  }
}

解决方案 »

  1.   

    case 2:
            System.out.println("Value is two.");
    ------------------------------------------
    在这句后面加上  break;
    case 2:
            System.out.println("Value is two.");        break;
      

  2.   

    public class SwitchTest
    {
      public static void main(String[] args)
      {
        int j = 2;
        switch ( j )
        {
          case 2:
     修改处 System.out.println("Value is two.");
          break;
          case 10:
            System.out.println("Value is three.");
            break;
          default:
            System.out.println("Value is " + j);
            break;
        }
      }
    }
      

  3.   

    好奇怪的问题
    为什么你能记得在case 10后面家break,而想不起来在case 2后面也加上呢??#
      

  4.   

    原谅一下,可能是菜鸟,我以前学C的时候班里同学比这CUO 的都有。
      

  5.   

    case 2:
            System.out.println("Value is two.");
    后面加个break;
      

  6.   

    oyp254710980 说的那样就是了