Enter any integer of whch you want to find factorial as an input. Now we use for loop to calculate the factorial of given number.
Here is the source code of the Java Program to Find Factorial Value Without Using Recursion. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Factorial
public static void main(String args)
int n, mul = 1;
Scanner s = new Scanner(System.in);
System.out.print("Enter any integer:");
n = s.nextInt();
for(int i = 1; i <= n; i++)
mul = mul * i;
System.out.println("Factorial of "+n+" :"+mul);
$ javac Factorial.java $ java Factorial Enter any integer:8 Factorial of 8 :40320
Sanfoundry Global Education & Learning Series – 1000 Java Programs.