// Given the value of N , find the Nth Fibonacci Number
import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static int strg[]; // Global Variable
public static int fib_memoisation(int n){
if( n == 0 || n == 1){
strg[n] = n ;
return n;
}
if(strg[n] != -1){
return strg[n];
}
int a = fib_memoisation(n-1);
int b = fib_memoisation(n-2);
strg[n] = a + b ;
return strg[n];
}
public static int fib(int n ){
strg = new int[n+1];
Arrays.fill(strg , -1 );
return fib_memoisation(n);
}
public static void main(String[] args) {
int n = 10;
System.out.println("Fibonacci(" + n + ") in Dynamic Programming approach = " + fib(n));
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: