For Loop-rabbit breeding problem, for Rabbit Breeding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.