//找出刚刚好比输入数字大的兔子数
public static void main(String[] args) {
//定义,表明兔子数列的特性
int f0=0,f1=1,f2=f0+f1,a;
Scanner scanner = new Scanner(System.in);
System.out.println("输入数字我能找出刚刚好大于它的兔子数");
a= scanner.nextInt();
//用从小到达的兔子数和输入的数字比大小(利用兔子数列特性)
while (f2<a){
f0=f1;
f1=f2;
f2=f0+f1;
}
//输出该数字
System.out.println(f2);
}
}
输出结果:
输入数字我能找出刚刚好大于它的兔子数
1596
1597
Process finished with exit code 0
原文链接: https://blog.csdn.net/daibadetianshi/article/details/136597771