Neon Number


Neon Number
------------------
Program to check a number is a neon number or not.
A neon number is a number where the sum of digits 
of square of the number is equal to the number.

 For Example if the input number is 9,
                  its square is 9*9 = 81
                    and
                   sum of the digits is 9.
                  i.e. 9 is a neon number.
               
// Source Code                 
import java.util.*;
public class NeonNumber
  {
      public static void main(String args[])
         {
             Scanner in=new Scanner(System.in);
             int num,rd,square,sum=0;
             System.out.print("Enter a Number To Check : ");
             num = in.nextInt();
           
             square=num*num;
           
             while(square!=0)
                {
                    rd=square%10;
                    sum=sum+rd;
                    square=square/10;                 
                    }
                 
             if(sum==num)
                {
                    System.out.print("It is a Neon Number . ");
                     }
             else
                {
                    System.out.print("It is Not a Neon Number . ");
                     }
               }
        }           
     
// Sample Input :
  Enter a Number To Check : 9
// Sample Output:
  It is a Neon Number .

// Sample Input :
  Enter a Number To Check : 5
// Sample Output:
  It is Not a Neon Number .



       

Post a Comment

0 Comments