递归:自己调用自己;
/*
* 斐波拉切数列1 1 2 3 5 8 13 21
* show(int )
* show(1)= 1
* show(2)= 1
* show(3)= show(1)+show(2)=2
* show(4)= show(3)+show(2)=3
* show(5)= show(4)+show(3)=5
*
* */
public class Test_递归 {
public static int show(int i){//i=5
if(i==1||i==2){
return 1;
}else{
return show(i-1)+show(i-2);
}
}
public static void main(String[] args) {
int show = show(300);
System.out.println(show);
}
}原文:http://flyblog.blog.51cto.com/10081495/1755391