Showing posts with label Neon number in Java. Show all posts
Showing posts with label Neon number in Java. Show all posts

Java program to check the Neon Number | JAVA POINT

 

Write a Java program to check that a given number is Neon number or not.


Neon number Java program



Neon number

A number is said to be a Neon Number if the sum of digits of the square of the number is equal to the number itself.


PROGRAM :


import java.util.*;

public class neon

{

    public static void main(String args[])

    {

        Scanner ob=new Scanner(System.in);

        System.out.print("\nEnter the number to be checked : ");

        int num=ob.nextInt();

        int square=num*num;

        int sum=0;

        while(square!=0)//Loop to find the sum of digits.

        {

            int a=square%10;

            sum=sum+a;

            square=square/10;

        }

        if(sum==num)

        {

            System.out.println(num+" is a Neon Number.");

        }

        else

        {

            System.out.println(num+" is not a Neon Number.");

        }

    }

}

/*

Output :


Enter the number to be checked : 9

 9 is a Neon Number.

(Workings 9*9=81 sum of digits of square = 8 + 1 = 9.)

*/