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

编程问题,哪里出错了

public class HelloWorld {
    public static void main(String[] args) {
        char today='日';
        switch(today){
            case'一':
                '三':
                '五':
                System.out.println("油条");
                break;
            case'二':
                '四':
                '六':
                System.out.println("包子");
                break;
            case'日':
             System.out.println("主席套餐");
        }

提问者:明眸在心 2016-02-07 02:19

个回答

  • BitGhost
    2016-02-07 10:07:00
    已采纳

    一三五前面都要有case

  • 一条小咸鱼
    2016-02-16 23:21:14

    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;
            case '日':// 英文冒号
                System.out.println("主席套餐");
            }
        }// 少一个大括号
    }// 同上