Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java How To - Calculate Factorial of a Number?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ fact = 1;How To Calculate Factorial of a Number
Use a loop to calculate the factorial of a given number:
Example
int n = 5;
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
System.out.println("Factorial of " + n + " is " + fact);
// Output: Factorial of 5 is 120