static void Main(string[] args)
{
string[] name = new string[5];
int[] score = new int[5];
for (int i = 0; i < name.Length; i++)
{
Console.Write("请输入第" + (i + 1)+"位同学的姓名:");
name[i] = Console.ReadLine();
Console.Write("请输入第" + (i + 1) + "位同学的分数:");
score[i] = int.Parse(Console.ReadLine());
}
//计算总分和平均分
int sum = 0; int avg = 0;
for(int i=0;i<score.Length ;i++)
{
sum+=score[i];
}
avg = sum / score.Length;
Console.Write("总分:{0} ","平均分:{1}",sum,avg);
}
最后一段代码改为: Console.Write("总分:{0} 平均分:{1}", sum, avg); 或者把”{0}“和”平均分“之间的逗号改为加号,因为字符串连接用"+"。
Console.Write("总分:{0},平均分:{1}",sum,avg); 去掉","
谢谢!