C#实现九九乘法表

using System;
namespace 九九乘法表
{
 class MulTable
 {
  [STAThread]
  static void Main(string[] args)
  {
   DateTime startTime = DateTime.Now;
   Console.Write("设置乘法表的范围(整数)/n"
                +"n = ");
   int n = int.Parse(Console.ReadLine());
   MulTable m = new MulTable(n);
   System.TimeSpan t = DateTime.Now - startTime;
   Console.WriteLine("程序执行时间:" + t.ToString());
   Console.Write("Press ENTER to continue!");
   Console.ReadLine();
  }
  // 创建乘法表
  public MulTable(int n)
  {
   Console.WriteLine(
                "$$$$$$$$$$$$$$$$$$$$$$$$$乘法表$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
    );
   Console.WriteLine(
                "**************************************************************"
    );
   int wide = n<10?2:3;
   for(int i = 1;i < n+1;i++)
   {
    for(int j = 1;j <= i;j++)
    {
     Console.Write(SetWide(j,wide-1) + "*"
      + SetWide(i,wide-1) + "="
      + SetWide(i*j,wide)+ " ",j,i);
     //每一步用时0.01秒
     System.Threading.Thread.Sleep(10);
    }
    Console.WriteLine();//换行;
   }
   Console.WriteLine(
    "**************************************************************"
    );
  }
  // 设置数据宽度
  private string SetWide(int data,int wide)
  {
   string str = data.ToString();
   while(str.Length < wide)
   {
    str = str.Insert(str.Length," ");
   }
   return str;
  }
 }
}

你可能感兴趣的:(C#,程序设计)