Tail Recursion | Java Code for Tail Recursion ; A tail recursive function to calculate factorial ; A wrapper over factTR ; Driver code
class GFG { static int factTR ( int n , int a ) { if ( n == 0 ) return a ; return factTR ( n - 1 , n * a ) ; } static int fact ( int n ) { return factTR ( n , 1 ) ; } static public void main ( String [ ] args ) { System . out . println ( fact ( 5 ) ) ; } }