黑马程序员技术交流社区
标题:
二维数组。。。
[打印本页]
作者:
面朝大海,春暖
时间:
2013-10-7 19:05
标题:
二维数组。。。
本帖最后由 面朝大海,春暖 于 2013-10-7 20:09 编辑
如下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int[,] sum=new int[5,5];
Console.WriteLine("请输入:");
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
sum[i,j] =int.Parse(Console.ReadLine());
}
}
Console.ReadKey();
}
}
}
要求用户输入一个二维数组。。。。帮忙看看哪错了,先谢谢了。。
作者:
七里香
时间:
2013-10-7 19:54
没有报错,程序也能正常运行只是你没有输出语句吧{:soso_e127:}
作者:
为自己而战
时间:
2013-10-7 19:56
楼主你好:刚刚开始学习,我运行的这段代码没错啊,能连续输入25个数并存起来了。但是我觉得程序应该能让使用者知道输的数字是那个位置的。这是我加了点东西(能力有限,呼呼):
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
bool u=true;
while (u==true)
{
try
{
Console.WriteLine("请输入数组的行数(只能输入数字)");
int a = Convert.ToInt32(Console.ReadLine());//a存数组的行数信息
Console.WriteLine("请输入数组的列数");
int b = Convert.ToInt32(Console.ReadLine());//b存数组的列数信息
int[,] sum = new int[a, b];
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
Console.WriteLine("您输入的是第{0}行,第{1}列的数:", i + 1, j + 1);
sum[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("您已经输入完毕");
u = false;
Console.ReadKey();
}
catch (Exception err)
{
Console.WriteLine("请输入数字");
continue;
}
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2