這段程序在Visual Studio2010上運行后為什么的顯示不出來算數和與平均分?
?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);
? ? ? ? }
2016-05-09
最后一段代碼改為: Console.Write("總分:{0} ?平均分:{1}", sum, avg); 或者把”{0}“和”平均分“之間的逗號改為加號,因為字符串連接用"+"。
2018-07-25
Console.Write("總分:{0},平均分:{1}",sum,avg);? ?去掉","
2016-05-11
謝謝!