Factorial Number in JAVA
Program of Factorial Number
Program to calculate factorial of a number.
Factorial of a positive integer is the multiplication of all positive integers greater than 0 and smaller than or equal to the number. Factorial of a number is denoted by (!) sign.
Example : 5! = 5*4*3*2*1 = 120
Program below :-
import java.io.*;
import java.util.*;
class Factorial
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n,i,p=1;
System.out.println("Enter Number");
n= in.nextInt(); //Input number from user
for(i=1;i<=n;i++) //Loop from 1 to the entered number
{
p=p*i; // calculating factorial
}
System.out.println("Factorial of "+n+" is: "+p);//Printing result
} // end of main method
} // end of class
Comments
Post a Comment