各位大佬請幫我簡化下我的代碼,感覺有些復雜
?static void Main(string[] args)
??????? {
??????????? //聲明 兩組數組 ;
??????????? int[] score =new int[]{89,90,98,86,60,91,93,85};
??????????? string[] name = new string []{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
??????????? //聲明 分數中的 最大值;
??????????? int max = score[0];
??????????? //判斷出了最大的分數;
??????????? for (int i =0;i<score.Length;i++)
??????????? {
??????????????? max =max>score[i]?max:score[i];
??????????? }
??????????? //現在要判斷出分數的擁有者,即分數在數組中的具體位置
???????????? for(int j = 0;j<score.Length;j++)
???????????? {
???????????????? if(max == score[j])
???????????????? {
??????????????????? Console.Write("分數最高的是"+ name[j]+ ",分數是"+max);
???????????????????
???????????????? }
???????????? }
???
??????? }
2018-09-17
?static void Main(string[] args)
??????? {
??????????? //聲明兩組數組 ;
??????????? int[] score =new int[]{89,90,98,86,60,91,93,85};
??????????? string[] name = new string []{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
??????????? //聲明分數中的最大值和得分者;
??????????? int max = 0;
????????????string topName = null;
??????????? //判斷出了最大的分數;
??????????? for (int i =0;i<score.Length;i++)
??????????? {
? ? ? ? ? ? ? ? if (score[i]>max)
????????????????max =score[i];
????????????????topName = name[i];
??????????? }
??????????????????? Console.Write("分數最高的是{0},分數是{1}", topName, max);//輸入結果
???????????????????
????}
2018-10-14
static void Main(string[] args)
??????? {
??????????? //聲明兩組數組 ;
??????????? int[] score =new int[]{89,90,98,86,60,91,93,85};
??????????? string[] name = new string []{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
??????????? //聲明分數中的最大值和得分者;
??????????? int max = 0;
????????????string topName = null;
??????????? for (int i =0;i<score.Length;i++)? ?//判斷出了最大的分數;??????????? {
? ? ? ? ? ? ? ? if (score[i]>max)
? ? ? ? ? ? ? {
????????????????max =score[i];
????????????????topName = name[i];
? ? ? ? ? ? ? ?}
??????????? }
??????????????????? Console.Write("分數最高的是{0},分數是{1}", topName, max);//輸入結果
????????????????????
????}
2018-10-13
? ? ? ? ? ? int[] num =new int[8]{89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? string[] name = new string[8] { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關欣" };
? ? ? ? ? ? int max = 0;
? ? ? ? ? ? for (int i = 0; i < num.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? max = num[max] > num[i] ? max : i;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("分數最高的是{0},分數是{1}",name[max],num [max]);