In this section, we will discuss what is the neon numbers and also create a Java program to check if the given number is neon or not. Also, we will find all the neon numbers between a specified range.
Neon Number
A positive integer whose sum of digits of its square is equal to the number itself is called a neon number.
Example of Neon Number
Let's take an example and check 9 and 45 are neon numbers or not.
Steps to Find Neon Number
- Read an integer from the user or initialize a number (n) to check.
- Calculate the square of the given number (n) and store it in variable sq.
- Find the sum of the digits of the square (sq) and store the sum in the variable (sum).
- Compare the given number n with If both are equal, the given number is a neon number, else, not a neon number.
Neon Number Java Program
The logic is very simple. First, we have to calculate the square of the given number. After that, calculate the sum of digits in the square.
Let's create a Java program that checks if the given number is neon or not.
NeonNumberExample1.java
Output:
Let's find all the neon numbers between a specified range.
NeonNumberExample2.java
Output:
We get only three neon numbers between 0 to 100000. So, there is a probability that 1 Trillion also includes 0, 1, 9 as the neon numbers.
need an explanation for this answer? contact us directly to get an explanation for this answer