Kodekraftt
/Blog
/Neon Number In Java Definition Examples And Complete Program
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

Neon Number in Java: Definition, Examples, and Complete Program

A detailed guide on Neon Numbers in Java with definition, examples, logic explanation, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Neon Number in Java

A Neon Number is a special type of number in which the sum of the digits of its square is equal to the original number. It is a commonly asked question in Java programming assignments and coding interviews as it helps test loop logic, digit extraction, and mathematical thinking.

What Is a Neon Number?

A number n is called a Neon Number if:

Step 1 → Find square of n  
Step 2 → Sum the digits of the square  
If Sum == n → It is a Neon Number  
  

Example

Consider the number 9:

  • Square = 9 × 9 = 81
  • Digit sum = 8 + 1 = 9

Since the digit sum equals the number, 9 is a Neon Number.

How Do We Check a Neon Number in Java?

Steps to check a Neon Number:

  1. Accept the number from the user
  2. Find its square
  3. Extract digits of the square one by one
  4. Add all the digits
  5. Compare the sum with the original number

Java Program to Check Neon Number


import java.util.*;

public class NeonNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        int square = num * num;
        int sum = 0;

        while (square > 0) {
            int digit = square % 10;
            sum += digit;
            square /= 10;
        }

        if (sum == num) {
            System.out.println(num + " is a Neon Number.");
        } else {
            System.out.println(num + " is NOT a Neon Number.");
        }
    }
}

  

Example Walkthrough

Let's verify 9 step-by-step:

  • Square = 81
  • Digit extraction: 8, 1
  • Sum = 8 + 1 = 9

Since the sum equals the original number, it is a Neon Number.

Known Neon Numbers

Only a few Neon Numbers exist:

  • 0 → Square = 0, Sum = 0
  • 1 → Square = 1, Sum = 1
  • 9 → Square = 81, Sum = 9

These are the only Neon numbers in the positive integer range.

Practice Challenge

Write a Java program to find all Neon Numbers between 1 and 10,000. Loop through each number, apply the Neon logic, and print only the matching numbers.

You might also like

Disarium Number in Java: Definition, Examples, and Complete Program

A detailed explanation of Disarium Numbers in Java with definition, examples, step-by-step logic, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Fascinating Number in Java with Explanation, Definition, Examples, and Program

A Fascinating Number is a number which, when multiplied by 2 and 3 and then concatenated with itself, forms a string that contains all digits from 1 to 9 exactly once.

Check Perfect Square in Java Without Using Math.sqrt() – Explanation, Logic, Examples, and Program

Learn how to check whether a number is a Perfect Square in Java without using Math.sqrt(). This guide explains the logic, provides examples, and includes an efficient program using iterative checking.

Spy Number in Java — Definition, Logic, Examples, and Program

Learn what a Spy Number is in Java with clear explanations and examples. This blog covers the definition, logic, step-by-step approach, and a clean Java program to check whether a number is a Spy Number. Includes practice challenges to improve your number theory skills.

Automorphic Number in Java: Definition, Explanation, and Step-by-Step Program

A clear and detailed guide on Automorphic Numbers in Java, including definition, examples, logic breakdown, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Happy Number in Java

Learn what a Happy Number is and how to check whether a number is happy or not in Java. This guide explains the concept, algorithm, working process, dry run, and provides multiple Java programs for beginners.