Question
Check whether a number is a Neon Number
A neon number is a number where the sum of digits of the square of the number is equal to the number. For example, if the input number is 9, its square is 9*9 = 81 and the sum of the digits is 9. i.e. 9 is a neon number.
Enter a number:
9
9 is a Neon Number.
Example 2:
Enter a number:
303
303 is not a Neon Number.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
Java
Python
Java
import java.util.*;
public class NeonNumber
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to check neon number or not");
int num=sc.nextInt();
int squaredNumber=num*num;
int sum=0;
while(squaredNumber!=0)//Loop to find the sum of digits.
{
int a=squaredNumber%10;
sum=sum+a;
squaredNumber=squaredNumber/10;
}
if(sum==num)
{
System.out.println(num+" is a Neon Number.");
}
else
{
System.out.println(num+" is not a Neon Number.");
}
}
}
Python
number=int(input("Enter a number:"))
squareOfNumber=number**2
sumOfDigits=0
while(squareOfNumber>0):
rem=squareOfNumber%10
sumOfDigits=sumOfDigits+rem
squareOfNumber=squareOfNumber//10
if(sumOfDigits==number):
print(number,"is a neon number")
else:
print(number,"is not a neon number")