Neon Number – Java Program ICSE

Write a program to input a number and check if it is a neon number or not.

A number is said to be neon, if sum of all digits of the square of the number is equal to the number.
For example,
(1) Input   9,
It’s square => 9² = 81 . Now, 8+1 = 9 
So 9 is a Neon Number
(2)
Input   25,
It’s square = 625 = 6+2+5 = 13 
So 25 is not a Neon Number

import java.util.*;
class Neon
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n;
        System.out.println("Enter the number:");
        n=sc.nextInt();
          
        int s=n*n; //square of the number
        
        //sum of digits of the square
        int sum=0;
        while(s>0)
        {
            sum=sum+(s%10);
            s=s/10;
        }
        
        if(sum==n)
            System.out.println(n + " is a Neon number");
        else
            System.out.println(n + " is not a Neon number");
    }
}

1 thought on “Neon Number – Java Program ICSE”

Leave a Comment

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