總是顯示多出來一個人的成績,請幫我看看代碼
?string[] name = new string[] { "吳淞" ,"錢東宇","浮沉","陳璐", "周蕊","林日新" };
? ? ? ? ? ? ?int[] score = new int[] { 60, 56, 90, 89, 13, 56 };
? ? ? ? ? ? ?int max = 0;?
? ? ? ? ? ? ?for(int i=0;i<score.Length;i++)
? ? ? ? ? ? ?if (score[i]>max)
? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ?max = score[i];
? ? ? ? ? ? ? ? ?Console.WriteLine("{0}的成績最高,是{1}", name[i], max);
? ? ? ? ? ? ?}
2016-05-08
你這個代碼會把第一個人的名字輸進去。因為你的max初始值為0,不管是哪個同學的分數都比這個高,所以第一個同學的名字一定會出來,你把max的初始值設置成score[0]就好了。