The below method return 5 if you give n = 20.
My question is how is 1 incremented on each iteration?
mystery(10) + 1
= mystery(5) + 2
= mystery(2) + 3
= mystery(1) + 4
= mystery(0) + 5 = 5.
I am having some hard time with recursion.
public static int mystery(int n){
if(n <= 0){
return 0;
}else{
return mystery(n / 2 ) + 1;
}
}