Java program to find factorial of a number

Configurare noua (How To)

Situatie

In this program, you’ll learn to find the factorial of a number using for loop in Java.

Solutie

Pasi de urmat

public class Factorial {

public static void main(String[] args) {

int num = 10;
long factorial = 1;
for(int i = 1; i <= num; ++i)
{
// factorial = factorial * i;
factorial *= i;
}
System.out.printf(“Factorial of %d = %d”, num, factorial);
}
}

Output:

Factorial of 10 = 3628800

Tip solutie

Permanent

Voteaza

(8 din 20 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?