public class Main {
// I.
public static int f_I(int n)
{
int factorial = 1;
for (int i = n; i > 0; i--)
{
factorial *= n;
}
return factorial;
}
// II.
public static int f_II(int n)
{
int factorial = 1;
int j = 1;
while (j <= n)
{
factorial *= j;
j++;
}
return factorial;
}
// III.
public static int f_III(int n)
{
if (n == 1)
return n;
return n * f_III(n - 1);
}
public static void main(String[] args) {
// Harbor, Week 1, Mock 1, PR_PracticeTest_1.pdf
// AP CS A
// MCQ 17
System.out.println(f_I(3));
// Output: 27
// 27 is not equal to 3!
// 3! is 6.
System.out.println(f_II(3));
// Output: 6
// 3! is 6.
System.out.println(f_III(3));
// Output: 6
// 3! is 6.
}
}