← Unit 1 · all exercises
Saved in this browser only

Halve it twice

Take the number, halve it, then halve it again, and return the result. These are whole numbers, so anything left over is thrown away each time — and that means halving twice is not always the same as dividing by four.

int quarter(int n)

Solution.java
Loading editor…
Results

Examples

  • quarter(100) → 25
  • quarter(7) → 17 to 3 to 1

There are also 4 hidden tests you can't see. Solve the problem, not the examples.