天天看點

成績等級計算關鍵算法

輸入一批學生成績,以-1作為結束标記 。統計這批學生中,不及格(score<60)、及格(60<=score<70)、中等(70<=score<80)、良好(80<=score<90)、優秀(90<=score<=100)的人數。

注意:使用分支、循環結構語句實作。

package fouth;

import java.util.Scanner;

public class two {
    public static void main(String[] args) {
        int a=0,b=0,c=0,d=0,e=0;
        Scanner scanner=new Scanner(System.in);
        int score;
        do {
            System.out.println("請輸入學生成績:");
            score =scanner.nextInt();
            if (0<score && score<60){
                a++;
            }else if (60<=score && score<70){
                b++;
            }else if (70<=score && score<80){
                c++;
            }else if (80<=score && score<90){
                d++;
            }else if (90<=score && score<=100){
                e++;
            }
        }while (score!=-1);
        System.out.println("不及格的有"+a+"人");
        System.out.println("及格的有"+b+"人");
        System.out.println("中等的有"+c+"人");
        System.out.println("良好的有"+d+"人");
        System.out.println("優秀的有"+e+"人");







    }
}
      

  

路是自己的,沒必要拿别人的标準衡量自己,它隻配成為墊腳石。