1. 程式人生 > >最值、對應索引位置

最值、對應索引位置

http mage adk pre ring src spa names read

技術分享圖片

            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();

最值、對應索引位置