File tree Expand file tree Collapse file tree
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ //
You can’t perform that action at this time.
0 commit comments