package com.itperson;
/*
* The case of a rabbit giving birth to a rabbit;
* If there is a pair of rabbits, a pair of bunnies will be born every month from the third month, and the little rabbit will also give birth to a pair of bunnies every month from the third month
* Assuming that the rabbit does not die, ask how many pairs of rabbits are there in the 20th month
* first month: 1 pair
* second month: 1 pair
* third month: 2 pairs
* fourth month: 3 pairs
* fifth month Month: 5 pairs
* Sixth month: 8 pairs
* Seventh month: 13 pairs
* Regularity: Except for the first month and the second month, every other month is the sum of the previous two months
*/
public class FeiBoLaQiDemo {
public static void main(String[] args) {
System.out.println(method(20));
}
public static int method(int x){
if(x==1 || x==2) {
return 1;
}else{
//Repeatedly call
return method(x-1)+method(x-2);
}
}
}
/*
* The case of a rabbit giving birth to a rabbit;
* If there is a pair of rabbits, a pair of bunnies will be born every month from the third month, and the little rabbit will also give birth to a pair of bunnies every month from the third month
* Assuming that the rabbit does not die, ask how many pairs of rabbits are there in the 20th month
* first month: 1 pair
* second month: 1 pair
* third month: 2 pairs
* fourth month: 3 pairs
* fifth month Month: 5 pairs
* Sixth month: 8 pairs
* Seventh month: 13 pairs
* Regularity: Except for the first month and the second month, every other month is the sum of the previous two months
*/
public class FeiBoLaQiDemo {
public static void main(String[] args) {
System.out.println(method(20));
}
public static int method(int x){
if(x==1 || x==2) {
return 1;
}else{
//Repeatedly call
return method(x-1)+method(x-2);
}
}
}