Java划分学生成绩等级

  • 第一种方式是通过switch…case的方式进行,划分等级
  • 方式二是通过else if…的方式对等级进行划分
package com.demo1;

public class Test5 {
    public static void main(String[] args) {
        //5.根据学生成绩,进行评级,根据学生考试成绩划分ABCD(至少两种方式)
        int score=60;
        if (score>=0 && score<=100){
            switch (score/10){
                case 10:
                case 9:
                    System.out.println("A");
                    break;
                case 8:
                    System.out.println("B");
                    break;
                case 7:
                case 6:
                    System.out.println("C");
                    break;
                default:
                    System.out.println("D");
                    break;
            }
        }else{
            System.out.println("The Score error!");
        }

        if (score>=0 && score<=59){
            System.out.println("D");
        }else if (score>=60 && score<80){
            System.out.println("C");
        }else if (score>=80 && score<90){
            System.out.println("B");
        }else if (score>=90 && score<=100){
            System.out.println("A");
        }else {
            System.out.println("The Score Error!");
        }

    }
}