美文网首页IT
java 精算一

java 精算一

作者: 清风_d587 | 来源:发表于2018-08-02 09:51 被阅读3次

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

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

public class exp2{

public static void main(String args[]){

int i=0;

for(i=1;i<=20;i++)

System.out.println(f(i));

}

public static int f(int x)

{

if(x==1 || x==2)

return 1;

else

return f(x-1)+f(x-2);

}

}

public class exp2{

public static void main(String args[]){

int i=0;

math mymath = new math();

for(i=1;i<=20;i++)

System.out.println(mymath.f(i));

}

}

classmatht

public int f(int x)

{

if(x==1 || x==2)

return 1;

else

return f(x-1)+f(x-2)

加油联系我 

相关文章

网友评论

    本文标题:java 精算一

    本文链接:https://www.haomeiwen.com/subject/hkhjvftx.html