黑马程序员技术交流社区
标题:
递归方法如何使用??
[打印本页]
作者:
13120298870
时间:
2016-5-5 00:38
标题:
递归方法如何使用??
1.用递归实现不死神兔
故事得从西元1202年说起,话说有一位意大利青年,名叫斐波那契。
在他的一部著作中提出了一个有趣的问题:假设一对刚出生的小兔一个月后就能长成大兔,
再过一个月就能生下一对小兔,并且此后每个月都生一对小兔,一年内没有发生死亡,
问:一对刚出生的兔子,一年内繁殖成多少对兔子?
作者:
zhaokai123456
时间:
2016-5-5 00:49
1 1 2 3 5 8
作者:
13120298870
时间:
2016-5-7 23:22
zhaokai123456 发表于 2016-5-5 00:49
1 1 2 3 5 8
貌似懂了
作者:
13120298870
时间:
2016-5-7 23:27
public static int getCount(int month){
}
作者:
13120298870
时间:
2016-5-7 23:31
system.out.println(getCount(12));
public static int getCount (int month){
if(month==1 || month==2){
return 1;
}
return getCount(month-1) +getCount (month-2);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2