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

不知道这里哪里错了

public class HelloWorld {

    public static void main(String[] args) {

char today='日';

seich(today){

    case "一":

         case "三":

         case "五":

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

         break;

         case"二":

         case "四":

         case"六":

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

          break;

          case "日":

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

          

         

}

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

        

}

}



提问者:AINIforever 2016-12-16 09:36

个回答

  • 流星雨_myself
    2016-12-16 21:11:55
    已采纳

    问题总结:

    1、java关键字写错。

    2、char('')、string(“”)理解不到位。

  • 流星雨_myself
    2016-12-16 21:09:32

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


  • 流星雨_myself
    2016-12-16 21:07:48

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


  • qq_他大舅他二舅都是他舅_0
    2016-12-16 10:57:27

    case' 一  '用单引号


  • XiHeLuminosity
    2016-12-16 09:52:09

    seich-->switch

    case "一"-->case '一':