Skip to content

Commit 8fbf7f1

Browse files
Add: NeonNumber algorithm with test class
1 parent 4ef6357 commit 8fbf7f1

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.thealgorithms.maths;
22

3-
import java.util.Scanner;
4-
53
public 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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)