123456789101112131415161718192021222324252627282930313233343536 |
- class TestSwitch01
- {
- public static void main(String[] args)
- {
- //switch
- //语法
- String m = "苹果";
- //格式
- switch(m){
- default:
- System.out.println("面头");
-
- case "面条":
- System.out.println("面条");
-
- case "米饭":
- System.out.println("米饭");
- break;
- case "米线":
- System.out.println("面条");
- break;
-
- }
- //注意
- // case 匹配值 char byte short int String 枚举 enum
- // case 穿透性
- //使用上 if语句对比
- // 常量值 使用 switch
- // 范围性的 if else
- }
- }
|