Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Explain this recursion method output to me?

$
0
0
This is the recursion method:

public int mystery (int k) {
	if (k == 1) return 0;
	else return (1 + mystery(k/2));
	}




where the method is called for k = 16

The output is 4 but I don't see how. I'm having a hard time understanding recursion. Anyone explain how this works?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>