慕瓜8005646
2018-12-17 20:08
名字和分数的数据类型这块儿不好弄啊。。
二维数组这个题不好弄,你定义string的到时候分数不好比较,你定义int但名字又是字符串,最好用两个数组分别装吧,大不了你下标对应就好,找出最高分是多少,在遍历一遍数组谁等于这个最高分,直接输出就ok
string[,] list = new string[8, 2] {
{ "吴松", "89" },
{ "钱东宇", "90" },
{ "伏晨", "98" },
{ "陈陆", "56" },
{ "周蕊", "60" },
{ "林日鹏", "91" },
{ "何昆", "93" },
{ "关欣", "85" }
};
int max = 0;
string maxname = "吴松";
for (int i = 0; i < list.GetLength(0); i++)
{
if (int.Parse(list[i, 1]) > max)
{
max = int.Parse(list[i, 1]);
maxname = list[i, 0];
}
}
Console.WriteLine("分数最高的是{0},分数是{1}", maxname, max);
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string[,] score = new string[,] {{"吴松","89"},{"钱东宇","90"},{"伏晨","98"},{"陈陆","56"},{"周蕊","60"}, {"林日鹏","91" },{"何昆","93"},{"关欣","85"}};
int max = 0;
int y = 0;
for (int x = 0;x < score.GetLength(0); x++ )
{
if (Convert.ToInt32(score[x, 1]) >max)
{
max = (Convert.ToInt32(score[x, 1]));
y = x;
}
}
Console.WriteLine("分数最高的是{0},分数是{1}",score[y,0],score[y,1]);
}
}
}
C#开发轻松入门
254118 学习 · 1459 问题
相似问题