Factorial of a number in Java

Java code to find the Factorial of a number.

Source code :

public class Factorial {

    public static void main(String []args) {
      int i,fact=1,num;
      num = 5;
 
    for(i=1;i<=num;i++)
      fact=fact*i;
 
    System.out.print("Factorial of "+num+ " is "+fact);
    }
}

Output :

Factorial of 5 is 120

Output :


                

Comments :