java流程控制05Switch选择结构

package com.Leo.struct;

public class SwitchDemo01 {
public static void main(String[] args) {
//case 穿透 //switch 匹配一个具体的值
char grade = 'B';

switch (grade){
case 'A':
System.out.println("优秀");
break;//可选
case 'B':
System.out.println("良好");
break;
case 'D':
System.out.println("再接再厉");
break;
case 'E':
System.out.println("挂科");
break;
default:
System.out.println("未知等级");

}
}

}
package com.Leo.struct;

public class SwitchDemo02 {
public static void main(String[] args) {
String name = "Leo";
//JDK7的新特性,表达式结果可以是字符串!!!
//字符的本质还是数字

//反编译 java---class(字节码文件)---反编译(IDEA)

switch (name){
case "Leo":
System.out.println("leo");
break;
case "yuan":
System.out.println("yuan");
break;
default:
System.out.println("弄啥嘞!");
}
}
}
posted @ 2021-06-09 08:44  Leoyuan  阅读(41)  评论(0编辑  收藏  举报