Neon Number in JAVA
Neon Number in JAVA
A Neon Number is a number whose sum of digits of square of the number is equal to the number.
Example : Input number is 9, its square is 9*9 = 81 and sum of the digits of square is 9. i.e. 9 is a neon number
Algorithm and Program below :-
ALGORITHM :-
- Get the number to check for Neon Number
 - Get the square of the number in another variable
 - Store the sum of digits of square number in a variable
 - Compare the sum of the digits with the number
 - If both are equal print "Neon Number"
 - If not print "Not a Neon Number"
 
PROGRAM below :-
import java.io.*;
import java.util.*;
class Neon
{
    public static void main(String args[])
    {
        Scanner in= new Scanner(System.in);
        int n,p,rev,s=0;
        System.out.println("Enter Number");
        n= in.nextInt(); // Input number from user
        p=n*n; // storing the square of the number
        while(p>0)
        {
            rev=p%10; // it extract last digit of the number
            s=s+rev; // store the sum of digits of square of original number
            p=p/10; // it extract all digit except the last
        }
        if(n==s) // if number is equal to the sum of its square's digits
        {
            System.out.println("It is Neon Number : "+n);
        }
        else
        {
            System.out.println("It is not Neon Number : "+n);
        }
    } // end of main method
} // end of class
Comments
Post a Comment