它试图逐个元素地获取输入,而不是逐行获取并显示为矩阵。 输入格式是
我想以3行3列的方阵形式输出
100
----------
010
----------
001
代码:
using System;
public class Exercise14
{
public static void Main()
{
int i,j;
int[,] arr1 = new int[3,3];
Console.Write("\n\nRead a 2D array of size 3x3 and print the matrix :\n");
Console.Write("------------------------------------------------------\n");
/* Stored values into the array*/
Console.Write("Input elements in the matrix :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
arr1[i,j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.Write("\nThe matrix is : \n");
for(i=0;i<3;i++)
{
Console.Write("\n");
for(j=0;j<3;j++)
Console.Write("{0}\t",arr1[i,j]);
}
Console.Write("\n\n");
}
}