Factorial Program

Factorial problems test loop skills and logic clarity — often asked to check iteration understanding.

Java Code
public class Factorial {
    public static void main(String[] args) {
        int num = 5;
        long fact = 1;

        // Multiply numbers from 1 to num
        for (int i = 1; i <= num; i++) {
            fact *= i;
        }

        System.out.println("Factorial of " + num + " is: " + fact);
    }
}
    
Output
Factorial of 5 is: 120