class FactorialRecursion { public static int factorial(int n) { //base case: return 1 (n = 1). if (n == 1) { return 1; } else { //recursive case: call n * factorial(n-1). //5 * 4 * 3 * 2 * 1 return n * factorial(n-1); } } public static void main(String[] args) { int n = 5; //Finding factorial and stores into f variable. int f = factorial(n); System.out.println(n+"! = "+f); } }