Skip to content

Commit e8fc048

Browse files
Add: NeonNumber algorithm with test
1 parent 4fbfca5 commit e8fc048

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/java/com/thealgorithms/maths/NeonNumber.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55
* A number whose sum of digits of its square equals the number itself.
66
* Example: 9 - 9^2 = 81 - 8+1 = 9
77
*
8-
* @see <a href="https://en.wikipedia.org/wiki/Recreational_mathematics">Wikipedia</a>
8+
* @see <a href="https://en.wikipedia.org/wiki/Recreational_mathematics">
9+
* Wikipedia</a>
910
*/
10-
public class NeonNumber {
11+
public final class NeonNumber {
1112

1213
private NeonNumber() {
1314
}
1415

16+
/**
17+
* Check if a number is a Neon number.
18+
*
19+
* @param number the input number
20+
* @return true if neon number, false otherwise
21+
*/
1522
public static boolean isNeon(final int number) {
1623
int square = number * number;
1724
int digitSum = 0;
1825
int temp = square;
1926
while (temp > 0) {
20-
digitSum += temp % 10;
27+
digitSum = digitSum + temp % 10;
2128
temp /= 10;
2229
}
2330
return digitSum == number;

0 commit comments

Comments
 (0)