在c#中打印2到12的乘法表

时间:2014-05-22 20:06:55

标签: c#

class Program
{
   static void Main(string[] args)
   {
      Console.WriteLine(" Multiplication Tables");

      for (int i = 2; i <= 12; i++)
      {
         for (int j = 1; j <= 10; j++)
         {
            Console.WriteLine("{0}*{1}={2}", i, j, i*j);
         }
         Console.ReadLine();
      }
   }
}

我想打印2到12的乘法表,上面的代码我只能打印一个表。我没理解为什么第一个循环计数器没有递增。 任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:5)

它在每个内循环之后等待输入。

卸下:

Console.ReadLine();

从外部循环中,将其添加到最后。

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(" Multiplication Tables");

        for (int i = 2; i <= 12; i++)
        {
            for (int j = 1; j <= 10; j++)
            {
                Console.WriteLine("{0}*{1}={2}", i, j, i*j);
            }
        }

        Console.ReadLine(); // <-- Both loops now complete
    }
}

答案 1 :(得分:-2)

/* multiply of 2 to 12;*/ 
using System;
namespace multiply
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            for (a=1; a <= 12; a++) {
                Console.Write("\n");
                for (b = 1; b <= 10; b++)
                {
                    Console.Write("\n "+a* b);

                }
            }
            Console.Read();
        }
    }
}