Switch的基础结构
public class SwitchDeom01 {
public static void main(String[] args) {
char s = 'C';
switch (s){
case 'A':
System.out.println("优秀");
break;
case 'B':
System.out.println("良好");
break;
case 'C':
System.out.println("一般");
break;
case 'D':
System.out.println("及格");
break;
default:
System.out.println("输入的等级错误,请重新输入");
}
}
}
//JDK7 之后的版本才支持字符串匹配
public class SwitchDemo02 {
public static void main(String[] args) {
String name = "狗";
switch (name){
case "猫":
System.out.println("猫");
break;
case "狗":
System.out.println("狗");
break;
case "鱼":
System.out.println("鱼");
break;
case "鸟":
System.out.println("鸟");
break;
case "虎":
System.out.println("虎");
break;
default:
System.out.println("匹配失败");
}
}
}
标签:case,基础,System,break,Switch,println,结构,public,out
From: https://www.cnblogs.com/GXEndeavor/p/18668166