Ask Question
21 March, 04:25

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. 21 March, 07:57
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers