For Loop-rabbit breeding problem, for Rabbit Breeding
Some people want to know how many pairs of rabbits can breed in a year? So we built a wall to lock a rabbit inside. It is known that a rabbit can have a rabbit every month, while a rabbit has had a rabbit every month since 3rd months after birth. If no death occurs within a year, how many pairs can a rabbit breed within a year (12 months? Analysis: Rabbit's rule is a series of numbers, such as 1, 1, 2, 3, 5, 8, 13, and 21 (implemented cyclically)
System. out. println ("logarithm of rabbit in 1st months: 1 ");
System. out. println ("logarithm of rabbit in 2nd months: 1 ");
Int f1 = 1, f2 = 1, f;
For (int I = 3; I <= 12; I ++ ){
F = f2;
F2 = f1 + f2;
F1 = f;
System. out. println ("day" + I + "month's rabbit logarithm:" + f2 );
}
Running result:
The logarithm of the rabbit in 1st months: 1
The logarithm of the rabbit in 2nd months: 1
Rabbit logarithm in 3rd months: 2
Rabbit logarithm in 4th months: 3
Rabbit logarithm in 5th months: 5
Rabbit logarithm in 6th months: 8
Rabbit logarithm in 7th months: 13
Rabbit logarithm in 8th months: 21
Rabbit logarithm in 9th months: 34
Rabbit logarithm in 10th months: 55
Rabbit logarithm in 11th months: 89
Rabbit logarithm in 12th months: 144