用java语言定义整数变量表示西游班唐僧、悟空、八戒、沙僧的语文、数学、英语成绩;计算他们的个人总分并打印,计算全班总分、平均分并打印;
时间: 2023-10-20 18:09:26 浏览: 91
```java
public class Score {
public static void main(String[] args) {
//定义整数变量表示四个人的成绩
int tangChinese = 80, tangMath = 90, tangEnglish = 85;
int wukongChinese = 90, wukongMath = 95, wukongEnglish = 92;
int bajieChinese = 70, bajieMath = 80, bajieEnglish = 75;
int shaChinese = 75, shaMath = 85, shaEnglish = 80;
//计算个人总分并打印
int tangTotal = tangChinese + tangMath + tangEnglish;
int wukongTotal = wukongChinese + wukongMath + wukongEnglish;
int bajieTotal = bajieChinese + bajieMath + bajieEnglish;
int shaTotal = shaChinese + shaMath + shaEnglish;
System.out.println("唐僧的总分为:" + tangTotal);
System.out.println("悟空的总分为:" + wukongTotal);
System.out.println("八戒的总分为:" + bajieTotal);
System.out.println("沙僧的总分为:" + shaTotal);
//计算全班总分、平均分并打印
int classTotal = tangTotal + wukongTotal + bajieTotal + shaTotal;
double classAvg = classTotal / 4.0;
System.out.println("全班的总分为:" + classTotal);
System.out.println("全班的平均分为:" + classAvg);
}
}
```
阅读全文