Sobes.tech
Intern — Middle

Determining the integer part of the square root of a number

livecode

Task condition

The method takes an integer n and returns its square root, discarding the fractional part (without rounding up).

Examples:

  • 9 → 3
  • 4 → 2
  • 5 → 2 (√5 ≈ 2.23, integer part — 2)
class Sqrt {
    public int calculateSqrt(int n) {
        // TODO
    }
}