Class 10 Class 9

Neon Number in Java

A Neon Number is a positive integer, which is equal to the sum of the digits of its square.

For example, 9 is a neon number, because 92 = 81, and the sum of the digits 8 + 1 = 9, which is same as the original number.

Write a program in Java to input a positive integer from the user, and check if that number is a Neon Number.

class Neon{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("N = ");
        int n = Math.abs(Integer.parseInt(br.readLine()));
        int s = n * n;
        int sum = 0;
        while(s != 0){
            int d = s % 10;
            sum += d;
            s /= 10;
        if(n == sum)
            System.out.println(n + " is a Neon Number.");
            System.out.println(n + " is not a Neon Number.");

By admin

I am a Computer Science teacher in one of the renowned schools in India. I teach Java programming language to my students, and I maintain a website

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.