File tree Expand file tree Collapse file tree
main/java/com/thealgorithms/maths
test/java/com/thealgorithms/maths Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33/**
44 * Neon Number algorithm.
55 * A number whose sum of digits of its square equals the number itself.
6- * Example: 9^2=81⇒ 8+1= 9
6+ * Example: 9 - 9^2 = 81 - 8+1 = 9
77 *
88 * @see <a href="https://en.wikipedia.org/wiki/Recreational_mathematics">Wikipedia</a>
99 */
@@ -12,12 +12,13 @@ public class NeonNumber {
1212 private NeonNumber () {
1313 }
1414
15- public static boolean isNeon (int number ) {
15+ public static boolean isNeon (final int number ) {
1616 int square = number * number ;
1717 int digitSum = 0 ;
18- while (square > 0 ) {
19- digitSum = digitSum + square % 10 ;
20- square /= 10 ;
18+ int temp = square ;
19+ while (temp > 0 ) {
20+ digitSum += temp % 10 ;
21+ temp /= 10 ;
2122 }
2223 return digitSum == number ;
2324 }
Original file line number Diff line number Diff line change 11package com .thealgorithms .maths ;
22
3- import org .junit .jupiter .api .Test ;
3+ import static org .junit .jupiter .api .Assertions .assertFalse ;
4+ import static org .junit .jupiter .api .Assertions .assertTrue ;
45
5- import static org .junit .jupiter .api .Assertions .* ;
6+ import org .junit .jupiter .api .Test ;
67
78public class NeonNumberTest {
89
910 @ Test
10- public void testIsNeonTrue (){
11- assertTrue (NeonNumber .isNeon (9 ));
12- assertTrue (NeonNumber .isNeon (1 ));
11+ public void testIsNeonTrue () {
1312 assertTrue (NeonNumber .isNeon (0 ));
13+ assertTrue (NeonNumber .isNeon (1 ));
14+ assertTrue (NeonNumber .isNeon (9 ));
1415 }
16+
1517 @ Test
16- public void testIsNeonFalse ()
17- {
18+ public void testIsNeonFalse () {
19+ assertFalse ( NeonNumber . isNeon ( 2 ));
1820 assertFalse (NeonNumber .isNeon (5 ));
1921 assertFalse (NeonNumber .isNeon (10 ));
20- assertFalse (NeonNumber .isNeon (25 ));
2122 }
22- }
23+ }
You can’t perform that action at this time.
0 commit comments