一队老耗子,每个月都生一对小耗子,小耗子长3个月,第四个月开始变成老耗子开始生,
假设所有耗子都不死,请问20个月之后共有多少只耗子?
public class 计算老鼠数量 { public static void main(String[] args) { // 4.一队老耗子,每个月都生一对小耗子,小耗子长3个月,第四个月开始变成老耗子开始生, // 假设所有耗子都不死,请问20个月之后共有多少只耗子?// int old = 2, first = 0,second = 0,third = 0,sum = 0; for(int i =1 ;i < 25 ; i++){ old = old + third; third = second; second = first; first = old; // System.out.println(old +" "+ third+" " + second+" "+ first); } System.out.println(old + third + second+ first); } }
原文地址:https://www.cnblogs.com/zjulanjian/p/10952782.html
时间: 2024-10-03 04:33:29