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

为什么错误

switch (today){     case '一': case '三': case '五': System.out.println("吃包子");                    break; case '二': case '四': case '六': System.out.println("吃油条");                    break; default: System.out.println("吃主席套餐"); } } } 这个为什么过不去啊 明明结果正确啊

提问者:qq_向阳的笨笨猪_0 2015-12-11 09:16

个回答

  • AJohnson
    2015-12-11 10:52:22
    已采纳

    String data;

    int today=3;

    switch(today)


    {

            

    case 1:

    case 3:

    case 5:

    data="吃包子";

    break;


    case 2:

    case 4:

    case 6:

    data="吃油条";

    break;

    default:

    data="吃主席套餐";


    }

    System.out.println(data);

    因为你可能没有说明今天星期几


  • 憨豆公子
    2015-12-13 16:48:03

    因为这种选择的条件只能是整数

  • 尾戒123
    2015-12-12 09:39:18

    public class HelloWorld {

        public static void main(String[] args) {

        String today='日';

    switch(today){

            case '一':

            case '三':

            case '五': System.out.println("吃包子");break;

            case '二':

            case '四':

            case '六':System.out.println("吃油条");break;

            case '日':System.out.println(" 吃主席套餐");break;

            default : break;

    }

            

            

    }

    }

    我的也是过不了,你过了吗?