=best-10,等級為A分數(shù)>=best-20,等級為B分數(shù)>=best-30,等級為C分數(shù)>=best-40,等級..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java編寫成績等級,最高分為best

發(fā)布時間:2020-08-06 12:54:04 來源:網(wǎng)絡 閱讀:513 作者:夢T醒 欄目:編程語言

題目:編寫一個程序,讀入學生成績,獲取最高分為best,然后其他等級值:
分數(shù)>=best-10,等級為A
分數(shù)>=best-20,等級為B
分數(shù)>=best-30,等級為C
分數(shù)>=best-40,等級為D
其他情況為F

import java.util.Scanner;

public class Grade 
{
    public static void main(String[] args) 
    {
        System.out.print("請輸入學生人數(shù):");
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();//輸入學生人數(shù)
        System.out.print("請輸入學生的成績:");
         double[] student=new double[n]; 
        for(int i=0;i<n;i++)
        {
            student[i]=input.nextDouble();//輸入成績
        }
        for(int i=0;i<n;i++)
        {
        System.out.println("Student"+i+"score is"+student[i]+"and grade is"+fac(i,n,student));
        }
    }
    public static char fac(int j,int ren,double[] student)//等級劃分函數(shù)fac
    {
        double best=max(ren,student);
        if(student[j]>=best-10)
        return 'A';
        else if(student[j]>=best-20)
        return 'B';
        else if(student[j]>=best-30)
        return 'C';
        else if(student[j]>=best-40)
        return 'D';
        else
            return 'F';
    }
    public static double max(int n,double[] student)//求最高分函數(shù)max
    {
        double max=student[0];
        for(int i=1;i<n;i++)
        {
            if(max>student[i])
                max=max;
            else
                max=student[i];
        }
        return max;
    }
}
向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI