//斐波那契数列 1,1,2,3,5,8,13……
class DiGuiDemo
{
public static void main(String[] args)
{
int sum=getSum(i);//i取值
System.out.println(sum);
}
public static int getSum(int num)
{
if (num == 1 || num == 2)
{
return 1;//初始值或者定义初始变量
}
int temp=getSum(num-1)+getSum(num-2);//递归关系
return temp;//递归数列的返回值
}
}
|