用Java求十个数的总分_用java写一个程序,计算10个学生的总分和平均分。

import java.io.*;

public class Test

{

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

int[] cs, es, ms;

for (int i=0; i<10; i++)

{

System.out.print("请输入第" + i + "位学生的语文成绩:");

cs[i] = scan.nextInt();

System.out.print("请输入第" + i + "位学生的英语成绩:");

es[i] = scan.nextInt();

System.out.print("请输入第" + i + "位学生的数学成绩:");

ms[i] = scan.nextInt();

}

for (int j=0; j<10; j++)

{

int sum = cs[j] + es[j] + ms[j];

int avg = sum/3;

System.out.println("学号    中文    英语    数学    总分    平均分");

System.out.println(j + "   " + cs[j] + "    " + es[j] +"    " + ms[j] + "     " + sum + "   " avg ");

}

}

}

有些细节可以自己改一下,avg 平均分可以自己改成 float 的

要是对输入排版有要求,要自己改了

更多追问追答

追问

为什么我这边不能运行????

追答

不是吧

追问

试了好几次,不能运行::>_<::>

追答

import java.util.Scanner;

public class Test

{

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

int[] cs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int[] es = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int[] ms = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

for (int i=0; i<10; i++)

{

System.out.print("请输入第" + (i+1) + "位学生的语文成绩:");

cs[i] = scan.nextInt();

System.out.print("请输入第" + (i+1) + "位学生的英语成绩:");

es[i] = scan.nextInt();

System.out.print("请输入第" + (i+1) + "位学生的数学成绩:");

ms[i] = scan.nextInt();

}

for (int j=0; j<10; j++)

{

System.out.println("学号 中文 英语 数学 总分 平均分");

System.out.println((j+1) + " " + cs[j] + " " + es[j] +" " + ms[j] + " " + (cs[j]+es[j]+ms[j]) + " " + (cs[j]+es[j]+ms[j])/3);

}

scan.close();

}

}

不好意思,之前没有认真考虑,也没有调试,现在的可以用了

温馨提示:答案为网友推荐,仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值