zoukankan      html  css  js  c++  java
  • 求兔子总数

    题目:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

    程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....

     1 package com.li.FiftyAlgorthm;
     2 
     3 /**
     4  * 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子小兔子长到第三个月后每个月又生一对兔子 假如兔子都不死,问每个月的兔子总数为多少?
     5  * 
     6  * 程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....
     7  * 
     8  * @author yejin
     9  */
    10 public class Rabbit {
    11     public static final int MONTH = 15;
    12 
    13     public static void main(String[] args) {
    14         long f1 = 1L, f2 = 1L;
    15         long f;
    16         for (int i = 3; i < MONTH; i++) {
    17             f = f2;
    18             f2 = f1 + f2;
    19             f1 = f;
    20             System.out.println("第" + i + "个月的兔子对数:");
    21             System.out.println("" + f2);
    22         }
    23     }
    24 }
  • 相关阅读:
    Django【进阶】信号
    Django【进阶】缓存
    exec,eval
    linux下磁盘分区、格式化、挂载
    Django【进阶】中间件
    Django【进阶】权限管理
    Django【进阶】FBV 和 CBV
    MySQL 进阶(待发布)
    Django【进阶】
    django 分页和中间件
  • 原文地址:https://www.cnblogs.com/justdoitba/p/7142348.html
Copyright © 2011-2022 走看看