switch-case

判断学生成绩
package Test;

public class Test4 {
    
    
    public static void main(String[] args) {
    
    
        int score = 78;
        switch (score/10){
    
    
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                System.out.println("不及格");
                break;
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                System.out.println("及格");
                break;
                //更优的解决方案

        }
        //更优的解决方案
        switch (score / 60){
    
    
            case 0:
                System.out.println("不及格");
                break;
            case 1:
                System.out.println("及格");
                break;

        }
    }
}

猜你喜欢

转载自blog.csdn.net/m0_49162312/article/details/107289311