一个数组:1,1,2,3,5,8,13,21...+m,求第30位数是多少?用递归实现;
一个数组:1,1,2,3,5,8,13,21...+m,求第30位数是多少?用递归实现;
求优化:
public static int a = 1;
public static int b = 1;
public static int c = 0;
public static int i = 1;
private static int get(int p)
{
if (p == 0 || p==1)
{
return 1;
}
if(i==p)
{
return b ;
}
i++;
c = a + b;
a = b;
b = c;
return get(p);
} 我猜这个是作业题