public class Test {
public int fib(int n)
{
if(n==1 || n==2)//当n=1或2时 返回1
{
return 1;
}
return fib(n-1)+fib(n-2);//返回前两项的和
}
public static void main(String[] args) {
Test t = new Test();
for (int i = 1; i <= 20; i++) {
System.out.printf ("fib(%d)=%d\n",i,t.fib(i));
}
}
}