Neon Number in Java


Write a program in Java to enter a number and check whether the number is ‘Neon’or not .a number is said to be ‘Neon’ if sum of the digits of square of a number is equal to the number itself.

//To check whether a number is Neon or not

class Ne
{
public static void main(String arg[])
{
int p,s=0,d,n;
System.out.println (“Enter the number :”);
n=Integer.parseInt(arg[0]);
p=0;
p=n*n;
do
{
d=p%10;
s=s+d;
p=p/10;
}
while(p!=0);
if(s==n)
System.out.println(“It is a Neon number”);
else
System.out.println(“It is not a Neon number”);
}
}

/*output:
Enter the no: 9
9 is neon number

In above program we enter the no 9
9 is Neon number because

9*9=81;
and  8+1=9*/

 

Related Posts

Comments are closed.