factorial program in java

factorial program in java

This is a Java program to find the factorial of a Number using for loop. There are many ways to calculate a factorial using Java programming language. Today we're going to talk about factorials and the most common ways to find factorial. Factorial Program in Java using Do While Loop. public class Factorial { public static void main(String args[]) {int i, fact=1; int number=5; for(i=1;i<=number;i++) { fact=fact*i; } System.out.println("Factorial of "+number+" is: "+fact); } } Save the above code with any filename and .java extension. Code Explanation: Started with two variables “i” and “fact”, with value 1, then “number” with 5, which is our number to calculate the factorial. Factorial Program using recursion in java In this example, we will see a Java program to find the factorial of any given input number. Java program to find factorial Given below is the java program to find factorial of the given number. In mathematics, the factorial of any non-negative number let’s say X, is denoted by X! Below are few ways to execute factorial program in java. A technique of defining the … Please mail your requirement at hr@javatpoint.com. Play Video.