64. JAVA Program to find the Factorial of a given number.
How does this program work?
- This program is used to find the factorial of a given number using JAVA.
- Factorial number is defined by the product of all the digits of given number.
- Factorial of 0 is always 1.
Here is the code
// Factorial Number.
import java.util.Scanner;public class Factorial
{
public static void main(String args[] )
{
int i,fact=1,number;
System.out.println("Enter a number:" );
Scanner obj=new Scanner(System.in );
number=obj.nextInt();
for ( i=1;i<=number;i++ )
{
fact = fact*i;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}