返回列表 發帖
  1. public class D1 {
  2.         D1(){
  3.                 System.out.println("費氏數列第12項:"+f(12));
  4.                 System.out.println("費氏數列第23項:"+f(23));
  5.                 System.out.println("費氏數列第37項:"+f(37));
  6.                 System.out.println("費氏數列第42項:"+f(42));
  7.         }
  8.         int f(int n)
  9.         {
  10.                 if(n<2)
  11.                         return n;
  12.                 else
  13.                         return f(n-2)+f(n-1);
  14.         }
  15.         public static void main(String[] args) {
  16.                 long s=System.currentTimeMillis();
  17.                 new D1();
  18.                 long e=System.currentTimeMillis();
  19.                 System.out.println("花費:"+(e-s)+"毫秒");
  20.         }
  21. }
複製代碼

TOP

返回列表