Menu
Topics Index
...
`


Control Statements > Iteration statements (Loops) >
Siva Nookala - 11 Apr 2016
This program calculates the factorial of the given number using for Loop In Java.

Factorial using for loop
class FactorialUsingFor
{
    public static void main(String arg[])
    {
        int factorial = 1;
        int number = 6;
        
        for(int i = 1; i <= number; i++)
        {
            factorial *= i;
        }
        
        System.out.println("Factorial of number " + number + " is " + factorial);
    
    }
}
OUTPUT

Factorial of number 6 is 720

DESCRIPTION

This program finds the factorial of the given number 6, by multiplying the variable factorial with various values of i - 1, 2, 3, 4, 5, 6. So at the end of the for loop the value of factorial will be 1 * 2 * 3 * 4 * 5 * 6 = 720

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App