In this, we are going to write a simple program for finding factorial of number in Java.
import java.util.*;
class demo
{
public static void main(String[] args)
{
long i, n, f = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
n = sc.nextInt();
for (i = 1; i <= n; i++)
{
f = f * i;
}
System.out.print("Factotrial: " + f);
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP