后端开发
2020-07-20 14:47
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]);
}
}
}
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);
你的max的值获取的应该是i的值,而不是score[i]
数组越界
C#开发轻松入门
254121 学习 · 1459 问题
相似问题