//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;
}
}
兔子繁殖问题Java实现
于 2021-07-26 13:58:15 首次发布