返回列表 發帖
  1. package lol;

  2. public class Main {

  3.         long s,e;
  4.         Main()
  5.         {
  6.                 s=System.currentTimeMillis();
  7.                 test1();
  8.                 test2();
  9.                 test3();
  10.                 e=System.currentTimeMillis();
  11.                 System.out.println("花費: "+(e-s)+" 毫秒");
  12.         }
  13.        
  14.         void test1()
  15.         {
  16.                 for(int i=1;i<=10000;i++)
  17.                 {
  18.                         System.out.println(i);
  19.                 }
  20.                 System.out.println();
  21.         }
  22.         void test2()
  23.         {
  24.                 StringBuilder sb=new StringBuilder();
  25.                 for(int i=1;i<=10000;i++)
  26.                         sb.append(i+"\n");
  27.                 System.out.println();
  28.         }
  29.         void test3()
  30.         {
  31.                 String n="";
  32.                 for(int i=1;i<=10000;i++)
  33.                         n+=i+"\n";
  34.                 System.out.println();
  35.         }
  36.         public static void main(String[] args) throws Exception{
  37.                 new Main();
  38.         }

  39. }
複製代碼

TOP

返回列表