怎么錯了啊??
static void Main(string[] args)
? ? ? ? {
? ? ? ? ? int [] score=new int[]{89,90,98,56,60,91,93,85} ;
? ? ? ? ? char []name=new char[]{"吳松","錢東宇","伏晨","程陸","周蕊","林日鵬","何昆","關(guān)欣"};
? ? ? ? ? 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("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}",name[k],score[i]);
2016-09-11
? ? ? ? ? ? int[] score = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? string[] name = new string[] { "吳松", "錢東宇", "伏晨", "程陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };?//首先char是字符,string才是字符串
? ? ? ? ? ? int k = 0;
? ? ? ? ? ? int max = score[0];
? ? ? ? ? ? for (int i = 0; i < score.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (score[i] > max)?//if里如果有多個語句的話要用括號括起來,不然k最后會等于score的數(shù)組長度,也就是k會定位到最后一個同學(xué)的名字
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = score[i];
? ? ? ? ? ? ? ? ? ? k = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", name[k], max);?//還有就是,i是for循環(huán)里的一個局部變量,在循環(huán)外面調(diào)用不到,但是max是全局變量,它存儲了score的最高分?jǐn)?shù),所以直接用max就好了
//加油吧,程序員。。。。
2025-01-07
string[,] chenji = { { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" },
? ? ? ? ? ? ? ? ? ? ? { "89", "90", "98", "56", "60", "91", "93", "85" } };
int max = 0;
int indx = 0;
for (int i = 0; i < (chenji.Length / 2); i++)
{
? ? if (int.Parse(chenji[1, i]) > max)
? ? {
? ? ? ? max = int.Parse(chenji[1, i]);
? ? ? ? indx = i;
? ? }
}
Console.WriteLine($"{chenji[0, indx]}, {max}");?
//string[] names = { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
//int[] scores = { 89, 90, 98, 56, 60, 91, 93, 85 };
//int max = 0;
//int idex = 0;
//for ( int i = 0; i < scores.Length; i++)
//{
//? ? if (scores[i] > max)
//? ? {
//? ? ? ? max = scores[i];
//? ? ? ? idex = i;
//? ? }
//}
//Console.WriteLine($"{names[idex]},{max}");
2016-09-23
我用的二維數(shù)組
string[,] scores = new string[2,8]{{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關(guān)欣"},{"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("分?jǐn)?shù)最高的是"+name+",分?jǐn)?shù)是"+max);