关于switch语句中||的用法

来源:4-6 Java条件语句之 switch

wxxx_

2016-02-24 16:22

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("吃主席套餐");
}
}
}


写回答 关注

4回答

  • 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后面接常量,而且只能是一个

Java入门第一季(IDEA工具)升级版

0基础萌新入门第一课,从Java环境搭建、工具使用、基础语法开始

1167352 学习 · 18630 问题

查看课程

相似问题