Need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need help

What is returned as a result of calling mystery(1)? public static int mystery (int x) { if (x == 5){ return x; } else { return mystery(x--) * 5; } } 1=StackOverFlowError 2=25 3=nothing 5=5

29th Sep 2019, 9:34 PM
Mr Kraber
Mr Kraber - avatar
3 Answers
+ 2
Run the code and find out!
30th Sep 2019, 2:58 AM
Jacob Heath
Jacob Heath - avatar
+ 1
It is a stack overflow as post increment is used, calling mystery(1) over and over, again and again.
1st Oct 2019, 3:53 PM
jtrh
jtrh - avatar
+ 1
The correct answer is 1 = StackOverFlowError
19th Jun 2020, 10:45 AM
Amr Azab
Amr Azab - avatar