qq_愿做你半世浮台_0
2016-09-10 18:21
static void Main(string[] args)
{
int [] score=new int[]{89,90,98,56,60,91,93,85} ;
char []name=new char[]{"吴松","钱东宇","伏晨","程陆","周蕊","林日鹏","何昆","关欣"};
int k=0;
int max=score[0];
for(int i=0;i<score.Length;i++)
{
if(score[i]>max)
max=score[i];
k=i;
}
Console.Write("分数最高的是{0},分数是{1}",name[k],score[i]);
int[] score = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };
string[] name = new string[] { "吴松", "钱东宇", "伏晨", "程陆", "周蕊", "林日鹏", "何昆", "关欣" }; //首先char是字符,string才是字符串
int k = 0;
int max = score[0];
for (int i = 0; i < score.Length; i++)
{
if (score[i] > max) //if里如果有多个语句的话要用括号括起来,不然k最后会等于score的数组长度,也就是k会定位到最后一个同学的名字
{
max = score[i];
k = i;
}
}
Console.Write("分数最高的是{0},分数是{1}", name[k], max); //还有就是,i是for循环里的一个局部变量,在循环外面调用不到,但是max是全局变量,它存储了score的最高分数,所以直接用max就好了
//加油吧,程序员。。。。
我用的二维数组
string[,] scores = new string[2,8]{{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"},{"89","90","98","56","60","91","93","85"}};
int max = 0;
string name=null;
for(int i=0;i<8;i++){
if(int.Parse(scores[1,i])>max){
max=int.Parse(scores[1,i]);
name = scores[0, i];
}
}
Console.Write("分数最高的是"+name+",分数是"+max);
C#开发轻松入门
254118 学习 · 1459 问题
相似问题