How to solve the Codewars's You're a square!

Today I try to solve the algorithm problem of codewars.


You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!

However, sometimes, you can’t arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things! If you just had a way to know, whether you’re currently working in vain… Wait! That’s it! You just have to check if your number of building blocks is a perfect square.

  • perfect square : N = n^2


  • isSquare(-1) -> false

  • isSquare(0) -> true

  • isSquare(3) -> false

  • isSquare(4) -> true

  • isSquare(25) -> true

  • isSquare(26) -> false


  • Math.floor() : return the largest integer that is less than or equal to the number.

  • Math.sqrt() : return the correctly rounded square root of a double value.

public class Square {    
    public static boolean isSquare(int n) {
        # Codewars COC 정책으로 인하여 코드 제거
Written on November 27, 2018