Solved

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

Question 56

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