Home

Tutoring

Subjects

Live Classes

Study Coach

Essay Review

On-Demand Courses

Colleges

Games


Sign up

Log in

Opening subject page...

Loading your content

Practice

  • All Subjects
  • Algebra Flashcards
  • SAT Math Practice Tests
  • Math Question of the Day
  • Live Classes
  • On-Demand Courses

Varsity Tutors

  • Find a Tutor
  • Test Prep
  • Online Classes
  • K-12 Learning
  • College Search
  • VarsityTutors.com

© 2026 Varsity Tutors. All rights reserved.

  1. Subjects ›
  2. AP Computer Science a ›
  3. Question of the Day

AP Computer Science a Question of the Day

AP Computer Science a Question of the Day

Answer today's AP Computer Science a question, reveal the full explanation, then keep the streak going with a new question every day.

A method public static int mystery(int n) contains the following algorithm: initialize a counter to 0, repeatedly divide n by 2 (ignoring remainders) while n is greater than 0, increment the counter each time, and return the counter value. What does this algorithm compute, and what will mystery(12) return?

Keep practicing AP Computer Science a

  • AP Computer Science a Flashcards
  • AP Computer Science a Quizzes
  • AP Computer Science a Practice Tests
  • AP Computer Science a Tutors
  • AP Computer Science a Test Prep

Question of the Day

A method public static int mystery(int n) contains the following algorithm: initialize a counter to 0, repeatedly divide n by 2 (ignoring remainders) while n is greater than 0, increment the counter each time, and return the counter value. What does this algorithm compute, and what will mystery(12) return?

  1. Computes the number of factors of 2 in n; returns 2 because 12 = 4 × 3 and 4 = 2²
  2. Computes the floor of log₂(n) plus 1; returns 4 because it counts division steps until reaching 0
  3. Computes the number of binary digits needed to represent n; returns 4 because 12 in binary is 1100 (correct answer)
  4. Computes the largest power of 2 less than n; returns 3 because 2³ = 8 is the largest power of 2 less than 12

Explanation: The algorithm repeatedly divides by 2 until reaching 0, counting steps. For n=12: 12→6→3→1→0 takes 4 steps. This counts binary digits because each division by 2 removes one binary digit. 12 = 1100₂ has 4 digits. Choice A confuses this with factoring. Choice B is close but describes it as log₂(n)+1 rather than binary digit count. Choice D misidentifies what's being computed entirely.