Examlex

Solved

What Is Wrong with the Following Recursive Method That Computes

question 27

Short Answer

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);
}


Definitions:

Egypt

A country in northeastern Africa known for its ancient civilization, pyramids, and the Nile River, with a rich historical and cultural heritage.

Greece

A country in southeastern Europe known for its rich history in philosophy, art, science, and democracy, as well as its ancient ruins and scenic landscapes.

Coordinating Services

The process of organizing and integrating services and resources across different sectors or organizations to ensure coherent and efficient delivery of care or assistance.

Case Manager

A professional responsible for planning, assessing, and coordinating care and services for individuals, often in health or social services contexts.

Related Questions