Tracing A Recursive Method
What does the program print when executed?
public class BitCount {
public static int countOnes(int n) {
if(n == 0) return 0;
return (n % 2) + countOnes(n/2);
}
public static void main(String[] args) {
System.out.println(countOnes(13));
}
}
A
3
B
2
C
4
D
5
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ngvandangthanh | 2 | 2 | 0m 00s | 200 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | lsj08030922 | 1 | 1 | 1m 26s | 14 |
| #4 | jeonsaw1723 | 1 | 1 | 2m 09s | -29 |
| #5 | patrickmeijer009 | 0 | 1 | 0m 51s | -61 |
| #6 | richa.tuli | 0 | 1 | 1m 36s | -106 |
| #7 | psak12 | 0 | 1 | 1m 56s | -126 |
| #8 | y.seong2027 | 2 | 3 | 10m 56s | -466 |
APFIVE