testmultable.java

来自「此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码」· Java 代码 · 共 41 行

JAVA
41
字号
// TestMulTable.java: Display a multiplication table
public class TestMulTable
{
  // Main method
  public static void main(String[] args)
  {
    // Get start time
    long startTime = System.currentTimeMillis();

    // Display the table heading
    System.out.println("       Multiplication Table");
    System.out.println("-----------------------------------");

    // Display the number title
    System.out.print("  | ");
    for (int j=1; j<=9; j++)
      System.out.print("  " + j);
    System.out.println(" ");

    // Print table body
    for (int i=1; i<=9; i++)
    {
      System.out.print(i+" | ");
      for (int j=1; j<=9; j++)
      {
        // Display the product and align properly
        if (i*j < 10)
          System.out.print("  " + i*j);
        else
          System.out.print(" " + i*j);
      }
      System.out.println();
    }

    // Get end time
    long endTime = System.currentTimeMillis();
    System.out.println("Elapsed time is " + (endTime - startTime)
      + " milliseconds");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?