A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

编写代码实现如下内容:用switch语句实现考试成绩分等级。
        [90-100]        A等。
        [80-90)         B等。
        [70-80)         C等。
        [60-70)         D等。
        [0-60)          E等。
        请根据给定成绩,输出对应的等级。
        说明:"["表示包含,")"表示不包含

2 个回复

倒序浏览
public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                while(true){
                        System.out.println("输入成绩");
                        int score = sc.nextInt();
                        int level = score / 10;
                        switch(level){
                                case 10:
                                case 9:
                                        System.out.println("A等");
                                        break;
                                case 8:
                                        System.out.println("B等");
                                        break;
                                case 7:
                                        System.out.println("C等");
                                        break;
                                case 6:
                                        System.out.println("D等");
                                        break;
                                case 5:
                                case 4:
                                case 3:
                                case 2:
                                case 1:
                                case 0:
                                        System.out.println("E等");
                                        break;
                                default:
                                        System.out.println("输入有误");
                                        break;
                        }
                }
        }
回复 使用道具 举报
1208124957 发表于 2016-7-25 01:33
public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                while(true){

很棒,谢谢大神
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马