package it.FileDemo;
/*
* 1,1,2,3,5,8,13,21....
* 斐波那契数列(黄金分割数列)
*/
public class TuZiDemo {
public static void main(String[] args) {
int num=20;
System.out.println(show(num));
System.out.println("-----------------");
int[] in=new int[num];
in[0]=1;
in[1]=1;
for (int i =2; i < in.length; i++) {
in[i]=in[i-1]+in[i-2];
}
System.out.println(in[19]);
}
public static int show(int n){
if(n==1 ||n==2){
return 1;
}
return show(n-1)+show(n-2);
}
}
|
|