Solved

What Is Wrong with the Following Recursive Sum Method? the Method

Question 7

Multiple Choice

What is wrong with the following recursive sum method? The method is supposed to sum up the values between 1 and x (for instance, sum(5) should be 5 + 4 + 3 + 2 + 1 = 15) .
Public int sum(int x)
{
If (x = = 0) return 0;
Else return sum(x - 1) + x;
}


A) the base case should return 1 instead of 0
B) the recursive case should return sum(x - 1) + 1; instead of sum(x - 1) + x;
C) the base case condition should be (x <= 0) instead of (x = = 0)
D) the recursive case should return sum(x) + 1;
E) the method should return a boolean instead of an int

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents