Neon Number in Java

Here in this tutorial you will learn how to check a neon number in Java.

What is a Neon Number?

Neon numbers are those numbers whose sum of the digits when squared is exactly the same as the number itself.

For example, the number 9.

Now the square of the number, 9 is 81. The sum of the digits in the square, 81 is 8 + 1 = 9, which is equal to the number itself.

Hence, the number 9 is a Neon number.

However, let the number is 11.

Now the square of the number, 11 is 121. The sum of the digits in the square, 121 is 1 + 2 + 1 = 4, which is not equal to the number itself.

Hence, the number 11 is NOT a Neon number.

Below is a program that inputs a number, and checks whether it is a Neon number or not.

Java Program to Check Neon Number

Output:

Enter a Number: 9
The number is a Neon number

The program runs a while loop to calculate the sum of the digits of the input number’s square.

Remember, sumOfDigits += square / 10; is the same as sumOfDigits = sumOfDigits + square / 10;

The program then just compares and see if the sum is in fact equal to the number itself.

There are only three neon numbers though: 0, 1 and 9.

Leave a Comment

Your email address will not be published. Required fields are marked *