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.
Import Java.util.arraylist;public class secondthread{ static arraylist<integer> list = new ArrayList (); int number;//count of rabbits after one months public static void Main (string[] args) { Secondthread st = new Secondthread (); St.fun (); St.out (); } private void Fun () {//The number of rabbits for 12 months is saved in the list linked list list.add (1); List.add (1); Rabbits in the first two months for (int i = 3;i<=12;i++) {Number = List.get (i-2) +list.get (i-3); List.add (number); } } private void Out () {//Output 12-month rabbit number int i =1; for (int j:list) { System.out.println ("+" + (i++) + "Rabbit number of months is" +j);}}}
Java program design of the BAE Bora series (Rabbit number of a year)