id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

norm.krumpe@muohio.edu homework9 > stepsToZero
prev  |  next  |  chance

In Java, if we begin with an int, divide it by 2, divide the result by 2, divide that result by 2, and so on, we eventually reach 0. For example, if we begin with 19 and repeatedly divide by 2, we get the following numbers: 9, 4, 2, 1, 0. It took 5 divisions to reach 0. Similarly, if we begin with -19 and repeatedly divide by 2, we get: -9, -4, -2, -1, 0. Given int n, determine how many steps it takes to reach 0.


stepsToZero(19) → 5
stepsToZero(-19) → 5
stepsToZero(0) → 0

...Save, Compile, Run (ctrl-enter)

public int stepsToZero(int n) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy