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 11package com .thealgorithms .maths ;
22
3- import java .util .Scanner ;
4-
53public class NeonNumber {
64
75 /**
86 * Check if a number is Neon Number.
97 * A neon number is a number where a sum of digits of its square equals the number itself.
108 * Example : 9--> 9^2 = 81 --> 8+1 = 9
11- *
9+ * @see <a href="https://en.wikipedia.org/wiki/Recreational_mathematics">
10+ * * Wikipedia - Recreational Mathematics</a>
1211 * @param number the number to check
1312 * @return true if neon number, else --> false
1413 */
@@ -24,18 +23,5 @@ public static boolean isNeon(int number)
2423 return digitSum == number ;
2524 }
2625
27- public static void main (String [] args ) {
28- Scanner scanner = new Scanner (System .in );
29- System .out .println ("Enter a number: " );
30- int number = scanner .nextInt ();
31-
32- if (isNeon (number )){
33- System .out .println (number + " is a Neon Numner " );
34- } else {
35- System .out .println (number + " is not a Neon Number " );
36- }
37- scanner .close ();
38- }
39- }
4026
41- //
27+ }
Original file line number Diff line number Diff line change 1+ package com .thealgorithms .maths ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import static org .junit .jupiter .api .Assertions .*;
6+
7+ public class NeonNumberTest {
8+
9+ @ Test
10+ public void testIsNeonTrue (){
11+ assertTrue (NeonNumber .isNeon (9 ));
12+ assertTrue (NeonNumber .isNeon (1 ));
13+ assertTrue (NeonNumber .isNeon (0 ));
14+ }
15+ @ Test
16+ public void testIsNeonFalse ()
17+ {
18+ assertFalse (NeonNumber .isNeon (5 ));
19+ assertFalse (NeonNumber .isNeon (10 ));
20+ assertFalse (NeonNumber .isNeon (25 ));
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments