Loading...
Loading...
Loading...
In how many ways can n students stand in a line for a class photo? The answer is n factorial: n! = 1 × 2 × 3 × ... × n. By definition 0! = 1.
Read n and print n!.
long.Example 1
Input
5
Output
120
1 × 2 × 3 × 4 × 5 = 120.
Example 2
Input
0
Output
1
0! is 1 by definition.
Try the problem first. Open one hint at a time.
Start a product at 1, not 0.
Multiply it by 2, 3, ..., n in a loop. Store it in a long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor