假设学生的三门课程分别为math、english和history,它们的平均分分别为mathAvg、englishAvg和historyAvg,学分分别为mathCredit、englishCredit和historyCredit。学生的总gpa可以用以下公式计算:

总gpa = (mathAvg * mathCredit + englishAvg * englishCredit + historyAvg * historyCredit) / (mathCredit + englishCredit + historyCredit)

其中,*表示乘法运算。

以下是Java实现:

double mathAvg = 85.5;
double englishAvg = 76.8;
double historyAvg = 92.3;
int mathCredit = 3;
int englishCredit = 4;
int historyCredit = 2;

double gpa = (mathAvg * mathCredit + englishAvg * englishCredit + historyAvg * historyCredit) / (mathCredit + englishCredit + historyCredit);
System.out.println("学生的总gpa为:" + gpa);

输出结果为:

学生的总gpa为:81.325
``
Java通过一个学生3门课程的平均分和学分计算他的总gpa

原文地址: https://www.cveoy.top/t/topic/epBB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录