问答详情
源自:4-6 Java条件语句之 switch

错哪里了。。。

public class HelloWorld {

    public static void main(String[] args) {

char today='日';

switch(today) {

    case '一';

    case '三';

    case '五';

    System.out.println("吃包子");

    break;

     case '二';

    case '四';

    case '六';

     System.out.println("吃油条");

    break;

    default:

    System.out.println("吃主席套餐");

}

    }

    

}

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

}

}

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

}

}


提问者:weixin_慕少9477067 2019-07-02 05:43

个回答

  • qq_慕勒0144734
    2019-07-02 19:24:33

    同楼上,是冒号" : "不是分号" ; ",注意区分中英文

  • 慕数据5907751
    2019-07-02 14:22:28

    case 语句后面是":"号,你大括号多3个,正确如下
    public class HelloWorld {    public static void main(String[] args) {char today='日';switch(today) {    case '一':    case '三':    case '五':    System.out.println("吃包子");    break;     case '二':    case '四':    case '六':     System.out.println("吃油条");    break;    default:    System.out.println("吃主席套餐");}}}


  • 粥啊
    2019-07-02 06:18:03

    case语句后面跟的是冒号":",不是分号";"