Which of the following code snippets returns the factorial of a given number? (Hint: Factorial of 5 = 5! = 1 * 2 * 3 * 4 * 5 = 120)
A) public static int factorial(int num)
{
Return num * factorial(num - 1) ;
}
B) public static int factorial(int num)
{
If (num == 1)
{
Return 1;
}
Return num * factorial(num) ;
}
C) public static int factorial(int num)
{
If (num == 1)
{
Return 1;
}
System.out.println(num * factorial(num - 1) ) ;
}
D) public static int factorial(int num)
{
If (num == 1)
{
Return 1;
}
Return num * factorial(num - 1) ;
}
Correct Answer:
Verified
Q77: Given the following method, what method call
Q78: Which of the following options represents the
Q79: For a program that reads three letter
Q80: What is incorrect in the following code
Q81: What is the output of the following
Q83: What is the output of the following
Q84: Given the method below, what is the
Q85: What is the output of the following
Q86: What is the output of the following
Q87: Based on the code snippet below, which
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents