mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 10:15:51 +08:00
Cleanup PerfectSquare
and its tests (#4992)
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user