We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1644db2 commit bdda4faCopy full SHA for bdda4fa
src/main/java/com/thealgorithms/maths/PerfectSquare.java
@@ -15,6 +15,9 @@ private PerfectSquare() {
15
* <tt>false</tt>
16
*/
17
public static boolean isPerfectSquare(final int number) {
18
+ if (number < 0) {
19
+ return false;
20
+ }
21
final int sqrt = (int) Math.sqrt(number);
22
return sqrt * sqrt == number;
23
}
@@ -27,6 +30,9 @@ public static boolean isPerfectSquare(final int number) {
27
30
* {@code false}
28
31
29
32
public static boolean isPerfectSquareUsingPow(long number) {
33
34
35
36
long a = (long) Math.pow(number, 1.0 / 2);
37
return a * a == number;
38
0 commit comments