Ask a New Question

Question

Consider the following code.
public static int recur3(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
return recur3(n - 1) + recur3(n - 2) + recur3(n - 3);
}
What value would be returned if this method were called and passed a value of 5?
3
9
11
16
5 years ago

Answers

oobleck
from the last statement,
r(5) = r(4)+r(3)+r(2)
r(4) = r(3)+r(2)+r(1)
r(3) = r(2)+r(1)+r(0)
So do the math
5 years ago
heh
Should be 9
3 years ago

Related Questions

icd-9-cm injury code and e codes for motor vehicle accident due to loss of control, and crashing int... Consider the following code. public void printNumbers(int x, int y) { if (x < 5) { System.o... What was the code name for the government program in which an atomic bomb was designed and construct... Hammurabi’s code was a code of _______. Please help me. Given the following code, what would the output on the final line be? # implementing Queue using Lis... How could the following code be adapted for a baseball score keeping? 1 def scoreUpdate(value): 2 #... What will the following code print? try: 5/0 except ZeroDivisionError: print("Ca... Why was the Code Talkers' code so hard to break? (1 point) Responses It was based on a language... Consider the following code segment, which is intended to assign to num a random integer value betwe... what is the e/m code for this scenario? Systemic lupus erythematosus with development of edema. H...
Ask a New Question
Archives Contact Us Privacy Policy Terms of Use