/** * Recursive algorithm * @author timmy1 * * */public class Recursion {/** * n factorial * @param n */public int factorial (int n) {if (n = 1) ) {return 1;} else{return n*factorial (n-1);} /** * @param Month Month * @return/public int rabbitgrow (int month) {if (Month ==1 | | month = 2) {//First month and second month only A pair of rabbits, by the third month, the rabbit began to breed a pair of rabbits return 1; }else{return Rabbitgrow (month-1) +rabbitgrow (month-2);} public static void Main (string[] args) {recursion recursion = new recursion ();//for (int i = 1;i < 10;i++) {//System The factorial result of Out.println (i+) is: "+recursion.factorial (i));" for (int i = 1;i < 12;i++) {System.out.println (i+) The number of rabbits in the month results in: "+recursion. Rabbitgrow (i)); } } }
Results Print:
January Rabbit Count Results: 1
February Rabbit Count Results: 1
March Rabbit Count Results: 2
April Rabbit Count Results: 3
May Rabbit Count Results: 5
June Rabbit Count Results: 8
July Rabbit count Results: 13
August Rabbit Count Results: 21
September Rabbit count Results: 34
October Rabbit count Results: 55
November Rabbit Count Results: 89