Java program design of the BAE Bora series (Rabbit number of a year)

Source: Internet
Author: User

Title: Classical Questions: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the rabbit long to the third month after the birth of a pair of rabbits, if the rabbit is not dead, ask each month the total number of rabbits?
1. Program Analysis: The law of Rabbits for the series 1,1,2,3,5,8,13,21 ....

Typical Pepolace the problem is not much to say, directly on the code good.

Importjava.util.ArrayList; Public classsecondthread{Staticarraylist<integer> list =NewArrayList (); intnumber;//number of rabbits counted after one months     Public Static voidMain (string[] args) {Secondthread St=NewSecondthread ();        St.fun ();    St.out (); }        Private voidFun () {//keep the number of rabbits for 12 months in the list linked listList.add (1); List.add (1);//number of rabbits in the first two months         for(inti = 3;i<=12;i++) { number= List.get (i-2) +list.get (i-3);        List.add (number); }    }        Private voidOut () {//number of rabbits that output 12 months        intI =1;  for(intj:list) {System.out.println ("First" + (i++) + "Rabbit number of months is" +j); }    }}

Java program Design of the PEI-Bora series (Rabbit number of years)

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.