top of page
Writer's pictureSatyam Gupta

Neon Number in JAVA

Neon Number


A Neon Number is a number whose sum of digits of square of the number is equal to the number.


Example : Input : 9

Square : 9*9 = 81 and

Sum of the digits of square : 8 + 1 = 9

Output : It 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 "It is Neon Number"

  • If not print "It is not a Neon Number"

 

Program :-


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

 

Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.

All the Best :)

Keep Learning :)

80 views1 comment

Recent Posts

See All

1 Comment


pardhu kantamani
pardhu kantamani
Mar 16

mystery java code in scanner class

Like
Post: Blog2_Post
bottom of page