Java Program to Check Whether a Number is Factorial or Not

Factorial of number in java. In this program you will learn how to write a program to print factorial number or not program in java using for loop. In the Java programming language, program a factorial number or not. This is a simple program that determines whether a number is factorial or not.

Long Keyword in Java

A minimum value of -263 and a maximum value of 263-1 may be found in the long. Long may now be represented as an unsigned 64-bit long with a minimum value of 0 and a maximum value of 264-1 in Java 8. 0L is the default value. It has an 8-byte default size. It’s utilised when you require an integer value with a larger range.

Factorial Number in Java Program

The product of all positive integers less than or equal to a particular positive integer, represented by that integer and an exclamation point in mathematics. As a result, factorial seven is expressed as 7!, which means 1 2 3 4 5 6 7. The factorial zero is equal to one. 

To get the factorial of a number, multiply it by the preceding number’s factorial value. For instance, to understand the value of 6! 720 is obtained by multiplying 120  by 6. For seven!. This is sample program for factorial of a number in java.

public class Main
{
public static void main(String[] args)
{
int num = 15;
long factorial = 1;
for(int i = 1; i <= num; ++i)
{
factorial = factorial * i;
}
System.out.printf("Factorial of %d is", factorial);
}
}

Output:

Factorial of 15 is 1307674368000