This is a Java Program to Find Factorial Value Without Using Recursion.
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.
import java.util.Scanner;
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);
}
}
Output:
$ javac Factorial.java $ java Factorial Enter any integer:8 Factorial of 8 :40320
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Apply for Computer Science Internship
- Practice Information Technology MCQs
- Check Java Books
- Check Programming Books
- Practice Programming MCQs