黑马程序员技术交流社区

标题: 二维数组。。。 [打印本页]

作者: 面朝大海,春暖    时间: 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个数并存起来了。但是我觉得程序应该能让使用者知道输的数字是那个位置的。这是我加了点东西(能力有限,呼呼):
  1. namespace ConsoleApplication4
  2.     {
  3.         class Program
  4.         {
  5.             static void Main(string[] args)
  6.             {
  7.                 bool u=true;
  8.                 while (u==true)
  9.                 {
  10.                     try
  11.                     {
  12.                         Console.WriteLine("请输入数组的行数(只能输入数字)");
  13.                         int a = Convert.ToInt32(Console.ReadLine());//a存数组的行数信息
  14.                         Console.WriteLine("请输入数组的列数");
  15.                         int b = Convert.ToInt32(Console.ReadLine());//b存数组的列数信息
  16.                         int[,] sum = new int[a, b];

  17.                         for (int i = 0; i < a; i++)
  18.                         {
  19.                             for (int j = 0; j < b; j++)
  20.                             {
  21.                                 Console.WriteLine("您输入的是第{0}行,第{1}列的数:", i + 1, j + 1);
  22.                                 sum[i, j] = int.Parse(Console.ReadLine());
  23.                             }  

  24.                         }
  25.                         Console.WriteLine("您已经输入完毕");
  26.                         u = false;
  27.                         Console.ReadKey();
  28.                     }
  29.                     catch (Exception err)
  30.                     {
  31.                         Console.WriteLine("请输入数字");
  32.                         continue;
  33.                     }
  34.                 }
  35.                
  36.                
  37.             }
  38.         }
  39.     }

复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2