- public class D1 {
- D1(){
- System.out.println("費氏數列第12項:"+f(12));
- System.out.println("費氏數列第23項:"+f(23));
- System.out.println("費氏數列第37項:"+f(37));
- System.out.println("費氏數列第42項:"+f(42));
- }
- int f(int n)
- {
- if(n<2)
- return n;
- else
- return f(n-2)+f(n-1);
- }
- public static void main(String[] args) {
- long s=System.currentTimeMillis();
- new D1();
- long e=System.currentTimeMillis();
- System.out.println("花費:"+(e-s)+"毫秒");
- }
- }
複製代碼 |