</pre><pre name="code" class="java">/*
【程序1】
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,
假如兔子都不死,问每个月的兔子总数为多少?
1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....
*/
class Yue
{
private int yue;
Yue(int yue)
{
this.yue = yue;
}
public int getYue()
{
return yue;
}
}
class RabbitNumber
{
public static int getNumber(int yue)
{
if (yue==1 || yue==2)
{
return 1;
}
else if (yue<1)
{
throw new FuShuException("没有这个月份");
}
else
{
return getNumber(yue-1)+getNumber(yue-2);
}
}
}
class FuShuException extends RuntimeException
{
FuShuException(String msg)
{
super(msg);
}
}
class Rabbit
{
public static void main(String[] args)
{
System.out.println(RabbitNumber.getNumber(new Yue(6).getYue()));
}
}</pre><pre name="code" class="java">/*
【程序1】