Recursive Function in Java

Introduction 

 
The below-given program lists the factorial of 1 to 20 and is a good example of Recursive Function in java:
 
Code
  1. public class RecursiveFunction {        
  2.         
  3.     public static void main(String[] args) {        
  4.         System.out.println("Number\t\tFactorial");        
  5.         for (int i = 0; i <= 20; i++) {        
  6.             System.out.println(i + "\t\t" + Factorial(i));        
  7.         }        
  8.     }        
  9.         
  10.     public static long Factorial(long x) {        
  11.         if (x == 0) {        
  12.             return 1;        
  13.         } else {        
  14.             return Factorial(x - 1) * x;        
  15.         }        
  16.     }        
  17. }       
Output
 
Number  Factorial 
 0
 1 1
 2
 3
 4 24 
 5 120 
 6 720 
 7 5040 
 8 40320 
 9 362880 
 10 3628800 
 11 39916800 
 12 479001600 
 13 6227020800 
 14 87178291200 
 15  1307674368000
 16  20922789888000
 17  355687428096000
 18  6402373705728000
 19  21645100408832000
  20  2432902008176640000