Factorial of a Number in Java

public class Factorial {
	public static void main(String[] args) {

		int inputNumber = 5;

		int factorial = inputNumber;

		for (int i = (inputNumber - 1); i > 1; i--) {
			factorial = factorial * i;
		}

		System.out.println("Factorial of " + inputNumber + "is : " + factorial);
	}
}
Output
Factorial of 5 is : 120










Related Examples


Write a program to check if an input String is Palindrome or not?
Calculate the factorial of a given number using Java?
How to reverse a number in Java?
Write a program to convert from decimal to binary?
Producer Consumer Example in Thread
Write a program to reverse a String?








Receive Latest Java Examples in Your Email: