Write a Program to print factorial of a number

public class Factorial{
     public static void main(String []args){
        int n = 5;
        int temp = 1;
        while (n>0)
        {
            temp = temp * n;
            n--;
        }
        System.out.println("Factorial of a number - " + temp);
        
     }
}

Output: –

Factorial of a number - 120

Leave a Reply

Your email address will not be published. Required fields are marked *