A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 13120298870 中级黑马   /  2016-5-5 00:38  /  929 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.用递归实现不死神兔
        故事得从西元1202年说起,话说有一位意大利青年,名叫斐波那契。
        在他的一部著作中提出了一个有趣的问题:假设一对刚出生的小兔一个月后就能长成大兔,
        再过一个月就能生下一对小兔,并且此后每个月都生一对小兔,一年内没有发生死亡,
        问:一对刚出生的兔子,一年内繁殖成多少对兔子?

4 个回复

正序浏览
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);
}
回复 使用道具 举报
public   static   int   getCount(int month){

}
回复 使用道具 举报

貌似懂了
回复 使用道具 举报
1 1 2 3  5 8
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马