/* Problem Description : Write a program to find the factorial of the given number A using recursion.
                    Problem Constraints :   0 <= A <= 12 */


import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    public int factorial(int A) {
        // Base Logic
        if (A == 0 || A == 1) {
            return 1;
        }
        return A * factorial(A - 1); // Recursive call to calculate factorial
    }

    public static void main(String[] args) {
        int n = 4; // The value for which you want to calculate the factorial
        Main main = new Main();
        int result = main.factorial(n);
        System.out.println("Factorial of " + n + " is: " + result);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: