/**
*
*/
package com.tjb.test;
/**
* @author tjbworkshop
*
*/
public class FeiBoLaQie {
/**
* @param args
*/
public static int FuncDG(int n)
{
if(n==0)
return 1;
else if(n==1)
return 1;
else if(n>1)
return FuncDG(n-1) + FuncDG(n-2);
else if(n<0)
System.out.println("n不符合要求!返回负1");
return -1;
}
public static int Func( int n )
{
int a = 1;
int b = 1;
int sum = 0;
if(n==0)
return 1;
else if(n==1)
return 1;
else if(n>1)
{
for(int i=2;i<=n;i++)
{
sum = a+b;
a = b;
b = sum;
}
return sum;
}
else if(n<0)
System.out.println("n不符合要求!,返回负1");
return -1;
}
public static void main(String[] args) {
// TODO 自动生成方法存根
long start1 = System.currentTimeMillis();
System.out.println(FuncDG(20));
long end1 = System.currentTimeMillis();
System.out.println("所用时间:"+(end1-start1));
long start2 = System.currentTimeMillis();
System.out.println(Func(20));
long end2 = System.currentTimeMillis();
System.out.println("所用时间:"+(end2-start2));
System.out.println(FuncDG(-1));
}
}