黑马程序员技术交流社区
标题:
(新手求解)C#中怎样在控制台中显示二维数组?
[打印本页]
作者:
为自己而战
时间:
2013-10-7 21:48
标题:
(新手求解)C#中怎样在控制台中显示二维数组?
本帖最后由 为自己而战 于 2013-10-8 12:08 编辑
清高手们讲一下用什么方法和思路吧~
作者:
王云峰
时间:
2013-10-8 01:35
用for循环就可以了啊,比如说有一个包含12345的int型数组,用下面的方法就可以在控制台输出12345了
int[] array={1,2,3,4,5};
for (int i = 0; i <array.Length; i++)
{
Console.WriteLine(array[i]);
}
复制代码
作者:
王云峰
时间:
2013-10-8 01:36
楼主如果问题解决了就把帖子设置成为 以解决,, 这样帮你的人才能得到技术分,谢谢
作者:
夏闯富
时间:
2013-10-8 08:56
本帖最后由 夏闯富 于 2013-10-8 09:00 编辑
控制台是一种傻瓜性质的输出,你想输出二维数组,必须先给输出结果布局好
int[,] a = new int[3, 5] { { 1, 2, 3, 4, 5 }, { 11, 22, 33, 44, 55 }, { 111, 222, 333, 444, 555 } };
Console.WriteLine("a的维度为:{0}", a.Rank);
Console.WriteLine("a的长度为:{0}", a.Length);
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
Console.Write("a[{0},{1}] = {2} \t", i, j, a[i, j]);
}
Console.WriteLine();
}
Console.ReadKey();
复制代码
作者:
面朝大海,春暖
时间:
2013-10-8 09:31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int[,] A = new int[3, 3];
Console.WriteLine("请输入9个数字");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
A[i, j] = int.Parse(Console.ReadLine());
}
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine();
for (int j = 0; j < 3; j++)
{
Console.Write(A[i,j]+"\t");
}
}
Console.ReadKey();
}
}
}
复制代码
我这儿也有一个,贴出来看看。。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2