recursive method in Java

logistic_guy

Senior Member
Joined
Apr 17, 2024
Messages
1,372
Write a recursive method that returns the number of \(\displaystyle 1\)’s in the binary representation of \(\displaystyle N\). Use the fact that this is equal to the number of \(\displaystyle 1\)’s in the representation of \(\displaystyle N/2\), plus \(\displaystyle 1\), if \(\displaystyle N\) is odd.
 
Write a recursive method that returns the number of \(\displaystyle 1\)’s in the binary representation of \(\displaystyle N\). Use the fact that this is equal to the number of \(\displaystyle 1\)’s in the representation of \(\displaystyle N/2\), plus \(\displaystyle 1\), if \(\displaystyle N\) is odd.
Please show us what you have tried and exactly where you are stuck.

Please follow the rules of posting in this forum, as enunciated at:

READ BEFORE POSTING

Please share your work/thoughts about this problem
 
Top