亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

各位大佬請幫我簡化下我的代碼,感覺有些復雜

?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);
???????????????????
???????????????? }
???????????? }
???
??????? }


正在回答

3 回答

?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);//輸入結果
???????????????????
????}


0 回復 有任何疑惑可以回復我~
#1

見微知著

if下面不加大括號的話,名字會輸出錯誤
2018-09-27 回復 有任何疑惑可以回復我~
#2

微風拂過v

為什么我for (int i =0;i<score.Length;i++)換成foreach(int i in score),程序就不好使了呢?
2018-10-15 回復 有任何疑惑可以回復我~

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);//輸入結果
????????????????????
????}


0 回復 有任何疑惑可以回復我~

? ? ? ? ? ? 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]);


0 回復 有任何疑惑可以回復我~
#1

微風拂過v

請問你寫的程序里 max = num[max] > num[i] ? max : i; 如果把?:換用if...else表達是怎樣的?
2018-10-15 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

各位大佬請幫我簡化下我的代碼,感覺有些復雜

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號