Program 1:
Classical question: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the small rabbit to the third month after the birth of a pair of rabbits each month, if the rabbit is not dead, ask each month the total number of rabbits?
1 /**2 * Fibonacci3 * Title: Classical questions: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the small rabbit to the third month after the birth of a pair of rabbits each month, if the rabbit is not dead, ask each month the total number of rabbits? 4 * 5 * @authorLangdao6 *7 */8 PackageOnetoten;9 ImportJava.util.Scanner;Ten Public classFibonacci { One Public Static voidMain (string[] args) { A //TODO auto-generated Method Stub -Scanner Scanner =NewScanner (system.in); -System.out.println ("Please enter months:"); the intn =scanner.nextint (); -System.out.println (Fibonacci) + ":" + fibonaccinormal (10)); - intsum = 0; - for(inti = 1; I <= N; i++) { +System.out.print (Fibonacci (i) + "\ T"); - } + } A //Recursive Implementation Method at Public Static intFibonacciintN) { - if(N <= 2) { - return1; -}Else { - returnFibonacci (n-1) + Fibonacci (n-2); - } in } - //recursive implementation of the way to Public Static intFibonaccinormal (intN) { + if(N <= 2) { - return1; the } * intN1 = 1, N2 = 1, sn = 0; $ for(inti = 0; i < n-2; i++) {Panax Notoginsengsn = n1 +N2; -N1 =N2; theN2 =SN; + } A returnSN; the } +}
Title serial number (to be)