eastwoodb3p23x1c eastwoodb3p23x1c
  • 06-01-2018
  • Advanced Placement (AP)
contestada

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)?

Respuesta :

cdw2014
cdw2014 cdw2014
  • 07-01-2018
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
Answer Link

Otras preguntas

What type of law is based on the roman law code?​
Solve the Equation p - 15 = 30.
Please i need help asap
A 1.0 mol sample of he(g) at 25 is mixed with a 1.0 mol sample of Xe(g) at 50 C. What would be the changes in average kineeteic energy and the average speed of
When 271. mg of a certain molecular compound X are dissolved in 25.0g of benzene C6H6, the freezing point of the solution is measured to be 0.5°C. Calculate the
CAN SOMEONE PLEASE HELP ITS EASY BUT IM D U M B
please help me with this
PLEASE HELP IM BEGGING PLEASE!!!!!!!!!!
(x/2-3)/5=6 convert to english sentence​
HELP PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!