File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .thealgorithms .maths ;
2+
3+ /**
4+ * This class checks whether a number is a Neon Number.
5+ * A Neon number is a number where the sum of digits of
6+ * its square is equal to the number itself.
7+ *
8+ * Example:
9+ * 9^2 = 81 → 8 + 1 = 9 (Neon Number)
10+ */
11+ public final class NeonNumber {
12+
13+ private NeonNumber () {
14+ // Prevent instantiation
15+ }
16+
17+ /**
18+ * Checks if a number is a Neon Number.
19+ *
20+ * @param number the input number
21+ * @return true if the number is a Neon Number, otherwise false
22+ * @throws IllegalArgumentException if the number is negative
23+ */
24+ public static boolean isNeon (int number ) {
25+ if (number < 0 ) {
26+ throw new IllegalArgumentException ("Number must be non-negative" );
27+ }
28+
29+ int square = number * number ;
30+ int sum = 0 ;
31+
32+ while (square > 0 ) {
33+ sum += square % 10 ;
34+ square /= 10 ;
35+ }
36+
37+ return sum == number ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments