美文网首页
switch语句不应该省略break;语句!

switch语句不应该省略break;语句!

作者: DesertSnow | 来源:发表于2017-05-11 13:56 被阅读0次
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