返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;

  3. public class P1 {
  4.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  5.         P1() throws Exception
  6.         {
  7.                  System.out.println("費氏數列第12項: "+f(12));
  8.          System.out.println("費氏數列第23項: "+f(23));
  9.          System.out.println("費氏數列第37項: "+f(37));
  10.          System.out.println("費氏數列第42項: "+f(42));
  11.         }
  12.         int f(int n)
  13.     {
  14.             if(n<2)
  15.                     return n;
  16.             else
  17.                     return f(n-2)+f(n-1);
  18.     }
  19.         public static void main(String[] args) throws Exception {
  20.                  long start=System.currentTimeMillis();
  21.          new P1();
  22.          long end=System.currentTimeMillis();
  23.          System.out.println("花費: "+(end-start)+" 毫秒");
  24.         }
  25. }
複製代碼

TOP

返回列表