-1
我需要填充一個數組並將該數組顯示到控制檯(以表格格式)。我如何顯示2D數組的表格?
這是我到目前爲止有:
static void Main()
{
//Declare variables, strings and constants.
const int ROWS = 10;
const int COLS = 5;
const int MIN = 1;
const int MAX = 100;
int total = 0;
int[,] numbers = new int[ROWS, COLS];
Random rand = new Random();
//Populate the array
for (int r = 0; r < ROWS; ++r)
{
for (int c = 0; c < COLS; ++c)
{
numbers[r, c] = rand.Next(MIN, MAX + 1);
}
}
//Display the array to console (table format)
for (int r = 0; r < numbers.GetLength(0); ++r)
{
for (int c = 0; c < numbers.GetLength(1); ++c)
{
Console.Write("{0,6} ", numbers[r, c]);
if (c % 5 == 0) Console.WriteLine();
}
}
當我這樣做,我的顯示器如果關閉的1,不爲10x5表正確對齊。
什麼是你的問題? – zerkms