为了账号安全,请及时绑定邮箱和手机立即绑定

请问这那错了

using System;

using System.Collections.Generic;

using System.Text;


namespace projGetMaxScore

{

    class Program

    {

        static void Main(string[] args)

        {

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

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

            int max=score[0];

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

            {

                if(score[i]<score[i+1])

                {

                    max=score[i+1];

                }

            }Console.WriteLine("分数最高的是{0},分数是{1}",name[max],score[max]); 

        }

    }

}


正在回答

3 回答

            string[,]  sor=new string[,]

            {{"吴松","89"},{"钱东宇","90"},{"伏晨","98"},{"陈陆","56"},{"周蕊","60"},{"林日鹏","91"},{"何昆","93"},{"关欣","85"}            };

            //Console.WriteLine(sor.GetLength(0));

            int Max = 0;

            string Name="";

            for (int i = 0; i < sor.GetLength(0)-1; i++)

            {

                if (int.Parse(sor[i, 1]) > Max)

                {

                    Max = int.Parse(sor[i, 1]);

                    Name = sor[i, 0];

                }

            }

            Console.WriteLine("分数最高的是" + Name + ",分数是" + Max);


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

你的max的值获取的应该是i的值,而不是score[i]


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

数组越界

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

举报

0/150
提交
取消
C#开发轻松入门
  • 参与学习       251620    人
  • 解答问题       1448    个

本门课程是C#语言的入门教程,将带你轻松入门.NET开发

进入课程

请问这那错了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信