Skip to content

Commit 4ef6357

Browse files
Add: NeonNumber algorithm in maths
1 parent e814d97 commit 4ef6357

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.thealgorithms.maths;
2+
3+
import java.util.Scanner;
4+
5+
public class NeonNumber {
6+
7+
/**
8+
* Check if a number is Neon Number.
9+
* A neon number is a number where a sum of digits of its square equals the number itself.
10+
* Example : 9--> 9^2 = 81 --> 8+1 = 9
11+
*
12+
* @param number the number to check
13+
* @return true if neon number, else --> false
14+
*/
15+
16+
public static boolean isNeon(int number)
17+
{
18+
int square = number*number;
19+
int digitSum = 0;
20+
while(square>0){
21+
digitSum += square % 10;
22+
square/= 10;
23+
}
24+
return digitSum == number;
25+
}
26+
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+
}
40+
41+
//

0 commit comments

Comments
 (0)