Memoization ( 1D , 2D and 3D ) | Java program to find the Nth term of Fibonacci series ; Fibonacci Series using memoized Recursion ; base case ; if fib ( n ) has already been computed we do not do further recursive calls and hence reduce the number of repeated work ; store the computed value of fib ( n ) in an array term at index n to so that it does not needs to be precomputed again ; Driver Code
import java . io . * ; class GFG { static int [ ] term = new int [ 1000 ] ; static int fib ( int n ) { if ( n <= 1 ) return n ; if ( term [ n ] != 0 ) return term [ n ] ; else { term [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ; return term [ n ] ; } } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( fib ( n ) ) ; } }