關于本節習題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _20180727
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string [] names =new string [8]{? "吳松" , "錢東宇", "伏晨" ,? "陳陸" , "周瑞" , "林日彭" , "何坤" ,? "關欣" };
? ? ? ? ? ? int[] score = new int[8] { 89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? int max = 0;
? ? ? ? ? ? int j= 0;
? ? ? ? ? ? for (int i = 0; i < score.Length;i++ )
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (max < score[i])
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = score[i];
? ? ? ? ? ? ? ? ? ? j = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("分數最高的是" + names [j]+"," + "分數是" + max );
? ? ? ? ? ??
? ? ? ? }
? ? }
}
我看到別人這樣寫,但是我不知道具體的意思,有大神能解釋這些語句嗎?謝謝
2018-08-11
不行,要初始化
2018-07-30
循環遍歷score數組所有的值,如果max變量小于當前score值就將score值附給max變量,數組遍歷完后max變量會獲得score數組中最大的值,之后輸出max即可;