开始有两只老鼠,每个月繁殖一对幼鼠,幼鼠三个月长大,即可繁殖,
问二十四个月后共有多少只老鼠(不考虑老鼠死亡、雌雄问题)?
package com.lovo.homework;
public class TestMouse {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int old = 2,first = 0, second = 0, third = 0;
for(int i = 0; i < 24; i++){
old = old + third;
third = second;
second = first;
first = old;
}
System.out.println(old + first + second + third);
}
}
时间: 2024-10-12 19:27:51