【程序1】
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
package com.share.test01_10;
/**
* 【程序1】题目:<br>
* 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,<br>
* 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死, 问每个月的兔子总数为多少?
*
* @author brx
*/
public class Test01 {
public static void main(String[] args) {
System.out.println(test(10));
}
/**
* 思路:这是一个斐波那契数列问题,<br>
* 1,1,2,3,5,8,13,21,34,55
*/
public static int test(int n) {
int result = 1;
if (n > 2) {
result = test(n - 1) + test(n - 2);
}
return result;
}
}
网友评论