[Offoffer] interview Title 4: Fibonacci Series

Source: Internet
Author: User

Question link: http://ac.jobdu.com/problem.php? Cid = 1039 & pid = 3

Description:

 
Description: we all know the Fibonacci series. Now we need to input an integer N. Please output the nth entry of the Fibonacci series. The Fibonacci series is defined as follows: input: the input may contain multiple test examples. For each test case, the input includes an integer N (1<= N <=70). Output: For each test case, the value of the nth Fibonacci series is output. Sample input: 3 sample output:2

 

Using biginteger in Java can solve the problem quickly, but I still get the runtime error result.

 Import java. Math. biginteger; import java. util. example;  /*  ** Question 4: Fibonacci series ** @ author yinger  */  Public   Class Nineoj_t4 {  Public   Static   Void  Main (string [] ARGs) {commandid = New Using (system. In  );  Int  N;  While  (Records. hasnextint () {n = Response. nextint (); system.  Out . Println (FAB (n ));}}  Public   Static Biginteger FAB ( Int  N ){  If (N = 0  ){  Return  Biginteger. Zero ;}  Else   If (N = 1  ){  Return Biginteger. One;} biginteger result = Biginteger. Zero; biginteger num1 = Biginteger. One; biginteger num2 = Biginteger. One;  For ( Int I = 1 ; I <n; I ++ ) {Result = Num2.add (num1); num1 = Num2; num2 = Result ;} Return  Result ;}} 

 

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.