Program to Calculate e ^ x by Recursion ( using Taylor Series ) | Java implementation of the approach ; Recursive Function with static variables p and f ; Termination condition ; Recursive call ; Update the power of x ; Factorial ; Driver code
import java . text . * ; class GFG { static double p = 1 , f = 1 ; static double e ( int x , int n ) { double r ; if ( n == 0 ) return 1 ; r = e ( x , n - 1 ) ; p = p * x ; f = f * n ; return ( r + p / f ) ; } public static void main ( String [ ] args ) { int x = 4 , n = 15 ; DecimalFormat df = new DecimalFormat ( "0 . # # # # # # " ) ; System . out . println ( df . format ( e ( x , n ) ) ) ; } }