//RubbitNum.java
package cn.campsg.java.experiment;
import java.util.Scanner;
public class RabbitNum {
public static void main(String[] args) {
System.out.println("请输入兔子繁殖的月份:");
Scanner in=new Scanner(System.in);
int month=in.nextInt();
in.close();
int num=rabbit(month);
System.out.println("第" + month + "个月,兔子数量是:" +num );
}
public static int rabbit(int month) {
int CNR=2;
int LNR=2;
int TNR=2;
for(int i=2;i<month;i++) {
if(month<=2) {
continue;
}
else {
CNR=LNR+TNR;
}
TNR=LNR;
LNR=CNR;
}
return CNR;
}
}
版权声明:本文为m0_50181189原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。