Search
 
SCRIPT & CODE EXAMPLE
 

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);
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: Deal with empty or blank cell in excel file using apache poi 
Java :: okhttp Sending and Receiving Network Requests 3 21 
Java :: java optional input for funktions 
Java :: Java offer() 
Java :: if(ResultSet.next()) 
Java :: jLabel copy 
Java :: When different programmers write the same program in differing ways and all get the correct result. what is that known as? 
Java :: Provide an ADT java class for one-dimension arrays named “MyArray” 
Java :: how to find the size of table in java 
Java :: luckperms api get usser by uuid 
Java :: Pattern using recursion in Java 
Java :: array erstellen java 
Java :: spring boot rest api 
Java :: jaggies 
Java :: how to get map with string as key and Arraylist as value in java 
Java :: illegal expression 
Java :: determine the distance between two circles in java 
Java :: rgb code from java color 
Java :: bukkit java get max players 
Java :: java binary search tree 
Java :: java importing 
Java :: java check if class is subclass 
Java :: when does black jack happens 
Java :: composite design pattern 
Java :: java division of 2 numbers with decimal places 
Java :: x = x + y; in java 
Java :: rest api client url not connecting to the database in spring boot 
Java :: android studio fecth audio from app directory 
Sql :: oracle nls_date_format 
Sql :: sql disable trigger 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =