Java Program to Find Factorial of a Number
Java Program to Find Factorial of a Number
Example of factorial of a number___ 5: 1*2*3*4*= 120
------------------------------------------------------------
import java.util.*;
class Factorial
{
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println(“Enter the number to print the factorial”);
int n=Sc.nextInt();
int p=1;
for(int i=n;i>=1;i- -)
{
p=p*I;
}
{
System.out.println(“The factorial is “+p);
} } }
Output: Enter
the number to print its factorial 10 public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println(“Enter the number to print the factorial”);
int n=Sc.nextInt();
int p=1;
for(int i=n;i>=1;i- -)
{
p=p*I;
}
{
System.out.println(“The factorial is “+p);
} } }
The factorial is 3628800
--------------------------------------------------------------------------------
Just copy paste the code into the class file of Bluej compiler. Change the class name according to your's.
Thanks for visting Programming in JAVA
Happy Coding !!
No comments: