⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5.2test.java

📁 介绍有关java的资料 课件 相当一本书籍 里面都是很基础的知识
💻 JAVA
字号:
// TestMulTableUsingStringBuffer.java: 测试字符串缓冲区
public class Test52
{
  // Main method
  public static void main(String[] args)
  {
    // Create a string buffer
    StringBuffer strBuf = new StringBuffer();

    // Get start time
    long startTime = System.currentTimeMillis();

    // Append the title to the buffer
    strBuf.append("       Multiplication Table" + '\n');
    strBuf.append("---------------------------------" + '\n');

    // Append the number title to the buffer
    strBuf.append("  | ");
    for (int j=1; j<=9; j++)
      strBuf.append("  " + j);
    strBuf.append('\n');

    // Append multiplication table body to the buffer
    for (int i=1; i<=9; i++)
    {
      strBuf.append(i + " | ");
      for (int j=1; j<=9; j++)
      {
        if (i*j < 10)
          strBuf.append("  "+i*j);
        else
          strBuf.append(" "+i*j);
      }

      strBuf.append(" " + '\n');
    }

    // Print the string buffer
    System.out.println(strBuf);

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

⌨️ 快捷键说明

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