Topic: If a pair of two-month-old rabbits can have a pair of rabbits each month, and a newborn rabbit born two months after the rabbit can be born. That means January is born in March to have children. Suppose the rabbit has no death in a year, how many pairs of rabbits a year later.
/**
* Using recursive algorithm to solve Fibonacci sequence: Fn = Fn-2 +fn-1;
* *
import java.util.*;
public class Fibonacci {public
static void Main (string[] args) {
System.out.println ("Recursive algorithm for solving rabbit birth Problems");
System.out.println ("Please enter the time:");
Scanner input =new Scanner (system.in);
int n = input.nextint ();
int num = Fibonacci (n);
System.out.println ("After the +n+" after a month, the total can breed into "+num+" to the rabbit. ");
}
public static int Fibonacci (int n) {
int t1,t2;
if (n==1| | n==2) {return
1;
} else {
T1 = Fibonacci (n-1);
T2 = Fibonacci (n-2);
return t1+t2;
}
}