Display the factorial

import java.util.*;
import java.util.Scanner;
class fact
{
public static void main(String args[])
{
int n,fact=1,i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number:");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.print("Factorial is"+fact);
}
}
OUTPUT:
Enter the number:
5
Factorial is 120
Translate »