Switch 选择结构
package zaiyang.struct;
public class SwitchDemo01 {
public static void main(String[] args) {
//case穿透 //switch 匹配一个具体的值
char grade = 'A';
switch (grade){
case 'A':
System.out.println("优秀");
break; //可选
case 'B':
System.out.println("良好");
break; //可选
case 'C':
System.out.println("及格");
break; //可选
case 'D':
System.out.println("再接再厉");
break;
case 'E': //可选
System.out.println("挂科");
break;
default:
System.out.println("未知等级");
}
}
}
package zaiyang.struct;
public class SwitchDemo02 {
public static void main(String[] args) {
String name = "会武功";
switch (name){
case "会武功的羊":
System.out.println("会武功的羊");
break;
case "追风的羊":
System.out.println("追风的羊");
break;
default:
System.out.println("连哥的名字都不知道");
}
}
}