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

要求结果是:
请输入学号 中英数成绩:1 80 70 90 
请输入学号 中英数成绩:
。。。
请输入学号 中英数成绩:
学号 中文 英语 数学 总分 平均分
…………………………………………………..
1 80 70 90 240 80
2 ….
3 ….
….
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();
}
}
不好意思,之前没有认真考虑,也没有调试,现在的可以用了

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-30
Scanner sc=new Scanner(System.in);
System.out.println("请分别输入语文,数学,英语成绩 以空格隔开");
int yuwenchengji=sc.nextInt();
int shuxuechengji=sc.nextInt();
int yingyuchengji=sc.nextInt();
int x,y;
z=(yuwenchengji+shuxuechengji+yingyuchengji)/3;
y=yuwenchengji+shuxuechengji+yingyuchengji;
System.out.println("该学生平均成绩为"+z);
System.out.println("该生总分为"+y);

兄弟应该是这样吧 可以了 望采纳 不是所有人都有这个闲心的追问

不运行O__O"…

追答

你是用的啥工具?我是netbeans

追问

vs2012

本回答被网友采纳