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)