Classical rabbit problems

Source: Internet
Author: User

Package com. MuMu. ready;

Import java. util. collections;

Public class rabbit {
// Question: classical question: there is a rabbit. every month from the first 3rd months after birth, a rabbit is born. After the third month, a rabbit is born every month. If the Rabbit does not die, what is the total number of rabbits per month?
// 1. program analysis: the rabbit rule is a sequence of numbers 1, 2, 3, 5, 8, 13, 21 ....
Public static void main (string [] ARGs ){
Pipeline can = new pipeline (system. In );
System. Out. println ("Enter the month :");
Int month = can. nextint ();
While (month <1) {// if it is set here, it will only judge once and will not judge the input again.
System. Out. println ("enter the correct month:"); // The correct month is a positive integer greater than 0.
Month = can. nextint ();
}
System. Out. println ("the total number of rabbits in this month is:" + f (month ));
}
Public static int F (INT m ){
If (M <3) return 1;
Else return F (S-1) + f (m-2 );
}
}

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.