In this program, you'll learn to find the factorial of a number using for and while loop in Java.This Java programming will teach you the methods for writing program to calculate factorial of any given number. First of all define a class "Factorial" under the Java util package. Java util package has a Scanner is used for reading the input . Take an integer variable as fact=1 and insert the message in the System method. Now applying for loop with conditions as integer i=1(intializer), i<=x and i++ as increment operator. So output result will be like fact=fact*i.
The factorial of a positive number n is given by:
factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n
Find Factorial of a Number Factorial in Java
When you run the program, the output will be:
Enter the Factorial Number :55 Factorial is = 120
إرسال تعليق
Thank you for vising