switch语句不应该省略break;语句!
public class SwitchDefaultTest {
public static void main(String[] args) {
char score = 'C';
switch (score) {
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("成绩输入错误");
// break;
}
}
}
javac -encoding utf-8 -Xlint:fallthrough SwitchDefaultTest
输出结果:
中
及格
不及格
成绩输入错误
本文标题:switch语句不应该省略break;语句!
本文链接:https://www.haomeiwen.com/subject/tkyotxtx.html
网友评论