C# score.GetLength(0),score.GetLength(1)
usingSystem.Windows.Forms;publicclassArray_test1{staticstringoutput;staticintminimum(...
using System.Windows.Forms;
public class Array_test1
{
static string output;
static int minimum(int[,] score)
{
int lowscore=100;
for (int i=0;i<score.GetLength(0);i++)
for(int j=0;j<score.GetLength(1);j++)
if(score[i,j]<lowscore)
lowscore=score[i,j];
return lowscore;
}
static int maximum(int [,] score)
{
int highscore=0;
for (int i=0;i<score.GetLength(0);i++)
for(int j=0;j<score.GetLength(1);j++)
if (score[i,j]>highscore)
highscore=score[i,j];
return highscore;
}
static double average(int[,] s,int k)
{
int total=0;
for(int i=0;i<s.GetLength(1);i++)
total +=s[k,i];
return (double) total/s.GetLength(1);
}
static void buildstring(int [,] score)
{
output +=" ";
for (int i=0;i<score.GetLength(1);i++)
output +=" 考试"+i+" ";
for (int i=0;i<score.GetLength(0);i++)
{
output +="\n 学生"+" ";
for (int j=0;j<score.GetLength(1);j++)
output +=score[i,j]+" ";
}
}
static void Main()
{
int[,] score={{100,80},{80,75},{95,80},{89,90},{98,88}};
output="数组是:\n";
buildstring(score);
output+="\n\n 最低分:"+minimum(score)+"\n 最高分:"+maximum(score)+"\n";
for (int i=0;i<score.GetLength(0);i++)
output +="\n 学生"+i+"的平均为:"+average(score,i);
MessageBox.Show(output, "输出结果");
}
}
score.GetLength(0),score.GetLength(1)为什么是0和1,表示什么意思 展开
public class Array_test1
{
static string output;
static int minimum(int[,] score)
{
int lowscore=100;
for (int i=0;i<score.GetLength(0);i++)
for(int j=0;j<score.GetLength(1);j++)
if(score[i,j]<lowscore)
lowscore=score[i,j];
return lowscore;
}
static int maximum(int [,] score)
{
int highscore=0;
for (int i=0;i<score.GetLength(0);i++)
for(int j=0;j<score.GetLength(1);j++)
if (score[i,j]>highscore)
highscore=score[i,j];
return highscore;
}
static double average(int[,] s,int k)
{
int total=0;
for(int i=0;i<s.GetLength(1);i++)
total +=s[k,i];
return (double) total/s.GetLength(1);
}
static void buildstring(int [,] score)
{
output +=" ";
for (int i=0;i<score.GetLength(1);i++)
output +=" 考试"+i+" ";
for (int i=0;i<score.GetLength(0);i++)
{
output +="\n 学生"+" ";
for (int j=0;j<score.GetLength(1);j++)
output +=score[i,j]+" ";
}
}
static void Main()
{
int[,] score={{100,80},{80,75},{95,80},{89,90},{98,88}};
output="数组是:\n";
buildstring(score);
output+="\n\n 最低分:"+minimum(score)+"\n 最高分:"+maximum(score)+"\n";
for (int i=0;i<score.GetLength(0);i++)
output +="\n 学生"+i+"的平均为:"+average(score,i);
MessageBox.Show(output, "输出结果");
}
}
score.GetLength(0),score.GetLength(1)为什么是0和1,表示什么意思 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询