斐波那契数列:
0 1 1 2 3 5 8 13 ......
前两个数之和等于后面一个数
如: 0+1=1
1+1=2
1+2=3
2+3=5
∶
∶
∶
public class Demo{
public static void main(String args[]){
System.out.println("斐波那契数列第1个数为0");
System.out.println("斐波那契数列第2个数为1");
com(0,1,2);
}
public static void com(int a,int b,int count) {
if(count==20) {
return;
}
b=a+b;
a=b-a;
System.out.println("斐波那契数列第"+(count+1)+"个数为:"+b);
com(a,b,count+1);
}
}