Logo

Programming-Idioms

Set the boolean b to true if the integer n is a square number, false otherwise

E.g. 2025true
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import static java.lang.Math.sqrt;
boolean b = sqrt(n) % 1 == 0;
math
b := round(sqrt(n)) ** 2 = n;
b := number mod (round(sqrt(number)) = 0;
import math
b = math.sqrt(n).is_integer()
class Integer
  def perfect_square?
    Integer.sqrt(self)**2 == self
  end
end

b = n.perfect_square?