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

  2.         Ch01()
  3.         {
  4.                 System.out.println("費氏數列第12項: "+f(12));
  5.                 System.out.println("費氏數列第23項: "+f(23));
  6.                 System.out.println("費氏數列第37項: "+f(37));
  7.                 System.out.println("費氏數列第42項: "+f(42));
  8.         }

  9.         int f(int n)
  10.         {
  11.                 if(n<2)
  12.                         return n;
  13.                 else
  14.                         return f(n-2)+f(n-1);
  15.         }

  16.         public static void main(String[] args) {
  17.                 long start=System.currentTimeMillis();
  18.                 new Ch01();
  19.                 long end=System.currentTimeMillis();
  20.                 System.out.println("花費: "+(end-start)+" 毫秒");
  21.         }

  22. }
複製代碼

TOP

返回列表