0

What is returned as a result of calling puzzle(22, 11)?

public static int puzzle(int i, int j) { if (i == j) { return 0; } else { return 1 + puzzle(i – 2, j – 1); } }

30th Jun 2018, 6:54 AM
VISHAL BHAUSAHEB PATIL
VISHAL BHAUSAHEB PATIL - avatar
3 Respostas
+ 2
11 i and j are decreasing by a factor of 2 and 1 respectively, intitially i = 22 and j = 11, recusion calling will stop when i==j, and it will reach when both i and j becomes 0, recusion call ocuurs 11 times, 10 times it gave 1 and it last it gave 0, so final result will be 1+1+.. 11times = 11
30th Jun 2018, 7:30 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 1
options are : StackOverFlowError 22 33 11
30th Jun 2018, 6:54 AM
VISHAL BHAUSAHEB PATIL
VISHAL BHAUSAHEB PATIL - avatar
0
help
30th Jun 2018, 7:14 AM
VISHAL BHAUSAHEB PATIL
VISHAL BHAUSAHEB PATIL - avatar