What is wrong with the following recursive method that computes the sum of all of the odd positive integers less than or equal to n?
public int sumOfOdds(int n) {
if(n%2 == 0)
return sumOfOdds(n-1);
else
return n + sumOfOdds(n-2);
}
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q26: A program with infinite recursion will act
Q27: What is recursion?
Q28: Write a recursive method that computes the
Q29: Write a recursive method that computes the
Q30: Recursion is necessary.
Q32: Write a recursive Java method that takes
Q33: The Fibonacci sequence is defined as the
Q34: In the Towers of Hanoi puzzle, it
Q35: Write the recursive definition of the factorial
Q36: Give a recursive definition of the sum
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