Title serial number (to be)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.