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?
What will be an ideal response?
```
public int sumOfOdds(int n)
{
if(n%2 == 0)
return sumOfOdds(n-1);
else
return n + sumOfOdds(n-2);
}
```
This method has no base case, and therefore running it would cause infinite recursion.
You might also like to view...
Which statement is false?
a) When a method call is made, the called method must know how to return to its caller, so the return address is pushed onto the program execution stack. b) Stacks support recursive method calls in the same manner as conventional, nonrecursive method calls. c) The program execution stack contains the space created for a method's global variables on each invocation of that method during a program's execution. d) When a method returns to its caller, the memory for that method's local variables is popped off the stack and those variables are no longer known to the program.
Designing a form with proper ________ can minimize the time and effort spent by employees in form completion.
A) flow B) usefulness C) context D) headings
Web application filenames in Visual Basic 2010 can include blank spaces.
Answer the following statement true (T) or false (F)
What is stored in ans as a result of the arithmetic expression, given the following declarations? int ans = 5, v1 = 2, v2 = 10, v3 = 18; ans += v1 + 10 * (v2-- / 5) + v3 / v2;
A. 27 B. 12 C. 29 D. none of the above