String[] names = { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何昆", "关欣" }; int[] scores = { 89, 90, 98, 56, 60, 91, 93, 85 }; int max = scores[0]; int index=0;//记录最大值索引位置 for (int i = 1; i < scores.Length; i++) { if (max < scores[i]) { max = scores[i]; index = i; } } Console.WriteLine("最高分为:"+max); Console.WriteLine("姓名是:" + names[index]); Console.ReadKey();
String[] names = { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何昆", "关欣" }; int[] scores = { 89, 90, 98, 56, 60, 91, 93, 85 }; int index = 0;//记录满足要求的索引位置 Console.WriteLine("及格的人是:"); for (int i = 0; i < scores.Length; i++) { if (scores[i]>=60) { index = i; Console.Write(names[i]+" "); } } Console.ReadKey();