1 switch case语句
switch(表达式) {
case 常量值1:
语句体1;
break;
case 常量值2:
语句体2;
break;
...
case 常量值n:
语句体n;
default:
语句体n+1;
}
2 switch case语句中表达式类型
public class SwitchCase {
public static void main(String[] args) {
String flag = "A";
switch (flag){
case "A":
System.out.println("A");
break;
case "B":
System.out.println("B");
break;
default:
System.out.println("Other");
}
}
}
public class SwitchCase {
public static void main(String[] args) {
int flag = 0;
switch (flag) {
case 0:
System.out.println(0);
break;
case 1:
System.out.println(1);
break;
default:
System.out.println("Other");
}
}
}