Following Program Illustrates the method of calculating Factorial of a Number:
import java.util.Scanner;
public class JavaApplication1
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Any Number to Calculate Factorial");
int f=1, a=input.nextInt();
for(int i=1;i<=a;i++)
{ f=f*i; }
System.out.println("Factorial is : "+f);
}
}
Output:
public class JavaApplication1
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Any Number to Calculate Factorial");
int f=1, a=input.nextInt();
for(int i=1;i<=a;i++)
{ f=f*i; }
System.out.println("Factorial is : "+f);
}
}
Output: