Factorial Program in Java


public class Factorial {

    public static void main(String[] args) {
        printFactorial(5);
    }
    
    public static void printFactorial(int n) {
        int factorial = 1;
        for(int i=1;i<=n;i++) {
            factorial = factorial * i;
        }
        System.out.println(factorial);
    }
}

Share this article on