问答详情
源自:6-1 练习题目

好像还有其他方式 看到网友写max,max 是关键字吗?

namespace test

{

    class Program

    {

        static void Main(string[] args)

        {

            string[] name = { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何昆", "关欣" };

            int[]score = { 89, 90, 98, 56, 60, 91, 93, 85 };

            int t = 0;

            string r = "";

            for (int i = 0; i < score.Length; i++)

            {

                if (score[i] > t)

                    t = score[i];

                    r = name[i];

            }

            Console.WriteLine("分数最高的是-" + r + ","  );

            Console.WriteLine("分数是-" + t);

        }

        

    }

}


提问者:qq_艾多比_五色鸟动漫_0 2018-09-12 13:19

个回答

  • 慕粉小萌新
    2018-09-12 15:13:02

    max 不是关键字,用到max 是因为要查找最高分啊

    代码供参考

    namespace projGetMaxScore
    {
        class Program
        {
            static void Main(string[] args)
            {
            string[]names={"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
            int[]score={89,90,98,56,60,91,93,88};
            int max=0;
            int n=0;
            for(int i=0;i<score.Length;i++)
            {
                if(score[i]>max)
                {
                    max=score[i];
                }
                else
                {
                    continue;
                }
                n=i;
            }
            Console.WriteLine("分数最高的是{0},分数是{1}",names[n],score[n]);
            }
        }
    }