mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
Add a new method to check Perfect Square (#5917)
This commit is contained in:

committed by
GitHub

parent
95875b0ae4
commit
921821214f
@ -18,4 +18,16 @@ public final class PerfectSquare {
|
||||
final int sqrt = (int) Math.sqrt(number);
|
||||
return sqrt * sqrt == number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a number is perfect square or not
|
||||
*
|
||||
* @param number number to be checked
|
||||
* @return {@code true} if {@code number} is perfect square, otherwise
|
||||
* {@code false}
|
||||
*/
|
||||
public static boolean isPerfectSquareUsingPow(long number) {
|
||||
long a = (long) Math.pow(number, 1.0 / 2);
|
||||
return a * a == number;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user