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

关于switch语句中||的用法

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


提问者:wxxx_ 2016-02-24 16:22

个回答

  • wxxx_
    2016-04-03 13:26:46

    public class wsq {

       public static void main(String[] args) {

    char today='日';

    switch (today){

           case ('一'|'五'|'三'):

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

           break;

           case ('二'|'四'|'六'):

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

           break;

           default:

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

    }

    }

    }

    换成这样就可以了,,不知为什么


  • XiaoQin_MK
    2016-02-24 16:41:19

    Case 后面只能为常量


  • 流浪_老
    2016-02-24 16:35:20

    不能这样的  你只能多写几个case  不能在case 后面用||

  • 我遇到我时变傻了
    2016-02-24 16:33:17

    case后面接常量,而且只能是一个