package com.example.demo.contorller; public class test1 { public static void main(String[] args) { //f(n) = f(n - 1) + f(n - 2)斐波那契约 //有一对兔子,第三个月就能生一对兔子,以后每个月这一对兔子都生一对兔子;新出生的兔子第三个月也能开始生兔子,也是之后每个月都生一对兔子 math ma=new math(); for (int i=1;i<=30;i++){ System.out.println(math.fmath(i)); } } } class math{ public static int fmath(int x){ if (x==1||x==2){ return 1; }else{ return fmath(x-1)+fmath(x-2); } } }
使用斐波那契数兔子
最新推荐文章于 2020-12-15 14:29:54 发布