為什么不對?
string []name=new string{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關(guān)欣"};
? ? ? ? ? ?int []score=new int{89,90,98,56,60,91,93,85};
? ? ? ? ? ?int max=89;
? ? ? ? ? ?int b=0;
? ? ? ? ? ?for(int i=1;i<8;i++)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?if(score[i]>max)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?max=score[i];
? ? ? ? ? ? ? ? ? ?b=i;
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",name[b],score[b]);
2018-07-10
你的代碼不夠全面。
我運行了一下。
你可以看一下這樣是正確的。
發(fā)現(xiàn)需要加上這樣的語句就可運行了。
你可以復制下面的語句在VS里面實際運行一下就可以了~~
哈哈
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
??? class Program
??? {
?????? ?
????? ?
?????? ?
??????? static void Main(string[] args)
??????? {
??????? ?
?????????? // string []name=new string{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關(guān)欣"};
??????? string[] name=new string[8]{"吳松","錢東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關(guān)欣"};
?????? ?
?????????? int []score=new int[8]{89,90,98,56,60,91,93,85};
?????????? int max=89;
?????????? int b=0;
?????????? for(int i=1;i<8;i++)
????????? {
?????????????? if(score[i]>max)
????????????? {
?????????????????? max=score[i];
?????????????????? b=i;
?????????????? }
?????????? }
?????????? Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",name[b],score[b]);
??????? }
??? }
}