switch多选择结构

 1 package com.lin.struct;
 2 
 3 public class SwitchDemo1 {
 4     public static void main(String[] args) {
 5         //case 穿透    //switch 匹配一个具体的值
 6         char grade = 'C';
 7 
 8         switch (grade){
 9             case 'A':
10                 System.out.println("优秀");
11                 break;//可选
12             case 'B':
13                 System.out.println("良好");
14                 break;
15             case 'C':
16                 System.out.println("及格");
17                 break;
18             case 'D':
19                 System.out.println("再接再厉");
20                 break;
21             case 'E':
22                 System.out.println("挂科");
23                 break;
24             default:
25                 System.out.println("未知等级");
26         }
27     }
28 }
 1 package com.lin.struct;
 2 
 3 public class SwitchDemo2 {
 4     public static void main(String[] args) {
 5         String name ="国王";
 6         //JDK7新特性,表达式结果可以是字符串!!!
 7         //字符的本质还是数字
 8 
 9         //反编译   java--class(字节码文件)--反编译(IDEA)
10         switch (name){
11             case "国王":
12                 System.out.println("国王");
13                 break;
14             case "皇后":
15                 System.out.println("皇后");
16                 break;
17             default:
18                 System.out.println("弄啥嘞!");
19 
20         }
21     }
22 }

 

posted @ 2021-02-11 15:43  奔啵儿灞  阅读(90)  评论(0)    收藏  举报