大多数人上学时候都接触过99乘法表,并且几乎都背诵过它的口诀。那么它在网页中如何实现的呢?(动态输出效果)
代码如下:

for (int i = 1; i < 10; i++)        // 控制行19

     {

       for (int j = 1; j <= i; j++)    // 控制列数

        {

          if (j == i)                 // 控制换行

 

Label1.Text += j.ToString() + "x" + i.ToString() + "=" + Convert.ToString(j * i) + "&nbsp" + "</br>";

                }

            else

             {

                Label1.Text += j.ToString() + "x" + i.ToString() + "=" + Convert.ToString(j * i) + "&nbsp";

               }

            }

        }

效果如下图:

 

把上面的乘法口诀表改成中文,代码如下图:

string [] a = { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " };    // 使口诀表中的数字变为文字

   string  sum;

   for (int i = 1; i < 10; i++)          // 控制行19

   { 

 for (int j = 1; j <= i; j++)                         // 控制列数

      {  sum = Convert .ToString (j * i);

        if (j * i < 10)         // 当“=”后面的值小于10

         {

            if (j == i)                 // 控制换行

              {

               Label1.Text += a[j] + a[i] + " " + a[(j * i)] + "&nbsp  " + "</br>";

                    }

                    else

                    {

                        Label1.Text += a[j] + a[i] + " " + a[(j * i)] + "&nbsp   " ;

                    }

                }

                else if (j * i == 10)                  // 当“=”后面的值等于10

             

                {

                    Label1.Text += a[j] + a[i] + a[Convert.ToInt32((sum.Substring(0, 1)))] + a[Convert.ToInt32((sum.Substring(1, 1)))] + "&nbsp   " ;

                }

                else                         当“=”后面的值大于10

                       if (j == i)                 // 控制换行

                    {

                        Label1.Text += a[j] + a[i]  + a[Convert.ToInt32((sum.Substring(0, 1)))] + " " + a[Convert.ToInt32((sum.Substring(1, 1)))] + "&nbsp    " + "</br>";

                    }

                    else {

                Label1.Text += a[j] + a[i] +a[Convert.ToInt32((sum.Substring(0, 1)))] + " " + a[Convert.ToInt32((sum.Substring(1, 1)))] + "&nbsp   " ;

                    }

                  }

        }

效果如下图