Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
hard Solved by 12 students

Tracing A Recursive Method

< Prev
Next >

What is printed to the console when the following program is 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

4

B

2

C

5

D

3

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1ngvandangthanh22 0m 00s 200
#2kaisuki12 0m 00s 90
#3demosolasis122 2m 44s 36
#4lsj0803092211 1m 26s 14
#5liuwilliam07241011 1m 30s 10
#6jeonsaw172311 2m 09s -29
#7ananyetyagi11 2m 38s -58
#8patrickmeijer00901 0m 51s -61
#9richa.tuli01 1m 36s -106
#10psak1201 1m 56s -126
Items per page:
10
1 – 10 of 12
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|FAQ