Search Your Topic

config
Friday, 07 December 2018 07:44

Program to check if number is Neon Number in java

Written by
Rate this item
(0 votes)

This program checks if a number entered is a Neon Number or not, in JAVA.

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.

Example- 9 is a Neon Number. 9*9=81 and 8+1=9.Hence it is a Neon Number.

Program - 

import java.util.*;
public class NeonNumber
{
    public static void main(String args[])
    {
        Scanner ob=new Scanner(System.in);
        System.out.println("Enter 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.");
        }
    }
}

Description - 

The number is entered through Scanner class and then its square is taken by multiplying the number 2 times.After that we find the sum of digits of the square and check if the number is equal to the sum of digits of square of the number.

Read 113 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Java Training

Facebook