Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

fibonacci for biginteger

import java.math.BigInteger;
import java.util.Scanner;

public class FibonacciRecursion {

    public static BigInteger fibonacci(int n) {
        if (n == 1 || n == 2) {
            return BigInteger.ONE;

        }else if(n==0){
            return BigInteger.ZERO;
        }
        else {
            return (fibonacci(n - 1).add(fibonacci(n - 2)));
        }

    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger ans = fibonacci(n);
        System.out.println(ans);
    }

}
 
PREVIOUS NEXT
Tagged: #fibonacci #biginteger
ADD COMMENT
Topic
Name
7+6 =