Java Program To Find Out The Factorial Of A Number
=====================================================================
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
// A factorial is a function that multiplies a number by every number below it
// till 1.
// Example : 1) 5! = 5*4*3*2*1
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number:");
Integer number = sc.nextInt();
Integer fact = 1;
for (int i = 1; i <= number; i++) {
fact = fact * i;
}
System.out.println("The Factorial Of the Number is :" + fact);
}
}
Output:
================
Enter the Number:
7
The Factorial Of the Number is :5040
Comments
Post a Comment