Ask Question
11 September, 13:51

Public static int recur (int x) { if (x > = 0) return x + recur (x - 1); return 0; } What is returned by the method call recur (9) ?

+4
Answers (1)
  1. 11 September, 14:09
    0
    9 > = 0 so return 9 + ...

    8 > = 0 so return 8 + ...

    7 > = 0 so return 7 + ...

    6 > = 0 so return 6 + ...

    5 > = 0 so return 5 + ...

    4 > = 0 so return 4 + ...

    3 > = 0 so return 3 + ...

    2 > = 0 so return 2 + ...

    1 > = 0 so return 1 + ...

    0 > = 0 so return 0 + ...

    -1 is not > = 0 so return 0.

    Now string together all the returns ...

    9+8+7+6+5+4+3+2+1+0+0=45

    recur (9) returns 45
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Public static int recur (int x) { if (x > = 0) return x + recur (x - 1); return 0; } What is returned by the method call recur (9) ? ...” in 📗 Advanced Placement (AP) if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers