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
Leave A Comment?