返回列表 發帖
  1. public class Ch100 {

  2.     long s, e;

  3.     Ch100()
  4.     {
  5.         s=System.currentTimeMillis();
  6.         //test1();
  7.         test2();
  8.         //test3();
  9.         e=System.currentTimeMillis();
  10.         System.out.println("花費: "+(e-s)+" 毫秒");
  11.     }

  12.     void test1()
  13.     {
  14.         for(int i=1; i<=10000; i++)
  15.             System.out.println(i);
  16.         System.out.println();
  17.     }

  18.     void test2()
  19.     {
  20.         StringBuilder sb=new StringBuilder();
  21.         for(int i=1; i<=10000; i++)
  22.             sb.append(i+"\n");
  23.         System.out.println(sb);
  24.     }

  25.     void test3()
  26.     {
  27.         String str="";
  28.         for(int i=1; i<=10000; i++)
  29.             str+=i+"\n";
  30.         System.out.println(str);
  31.     }

  32.     public static void main(String[] args) {
  33.         new Ch100();
  34.     }
  35. }
複製代碼

TOP

返回列表