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

  2.            Ch69()
  3.            {
  4.                    System.out.println("費事數列地12巷"+f(12));
  5.                    System.out.println("費事數列地12巷"+f(23));
  6.                    System.out.println("費事數列地12巷"+f(37));
  7.                    System.out.println("費事數列地12巷"+f(42));
  8.            }
  9. }
  10. int f(int n)
  11. {
  12.         if(n<2)
  13.                 return n;
  14.         else
  15.                 return f(n-2)+f(n-1);
  16. }
  17. public static void main(String[] args){
  18.         long start=System.currentTimeMills();
  19.         System.out.println("花費"+(end-start)+"毫秒");
  20.     }
  21. }
複製代碼

TOP

  1. public class Ch71 {
  2.     Ch71()
  3.     {
  4.             long data[]=new long[90];
  5.             data[0]=0;
  6.             data[1]=1;
  7.             for(int i=2;i<90;i++);
  8.             System.out.println("地12巷"+data[12]);
  9.             System.out.println("地23巷"+data[23]);
  10.             System.out.println("地37巷"+data[37]);
  11.             System.out.println("第42巷"+data[42]);
  12.             System.out.println("地59巷"+data[59]);
  13.             System.out.println("地89巷"+data[89]);
  14.            
  15.     }
  16.     public static void main(String[] args){
  17.             long start=System.currentTimeMillis();
  18.     new Ch71();
  19.     long end=System.currentTimeMillis();
  20.     System.out.println("spend"+(end-start)+"0.001sec");
  21.     }
  22. }
複製代碼

TOP

返回列表