Factorial of a Number:

public class Factorial {

 public static void main(String[] args) {

 int num = 5, factorial = 1;

 for(int i = 1; i <= num; ++i) {

 factorial *= i;

 }

 System.out.println(“Factorial of ” + num + ” is: ” + factorial);

 }

Output:

Factorial of 5 is: 120

Comments

Leave a Reply

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