Cleanup PerfectSquare and its tests (#4992)

This commit is contained in:
Piotr Idzik
2024-01-04 11:56:48 +01:00
committed by GitHub
parent 092ac5795b
commit 1ea95ffa92
2 changed files with 16 additions and 39 deletions

View File

@ -3,14 +3,8 @@ package com.thealgorithms.maths;
/**
* https://en.wikipedia.org/wiki/Perfect_square
*/
public class PerfectSquare {
public static void main(String[] args) {
assert !isPerfectSquare(-1);
assert !isPerfectSquare(3);
assert !isPerfectSquare(5);
assert isPerfectSquare(9);
assert isPerfectSquare(100);
public final class PerfectSquare {
private PerfectSquare() {
}
/**
@ -20,8 +14,8 @@ public class PerfectSquare {
* @return <tt>true</tt> if {@code number} is perfect square, otherwise
* <tt>false</tt>
*/
public static boolean isPerfectSquare(int number) {
int sqrt = (int) Math.sqrt(number);
public static boolean isPerfectSquare(final int number) {
final int sqrt = (int) Math.sqrt(number);
return sqrt * sqrt == number;
}
}