Question
Neon Number Between Given Range.
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.
Note:-0,1,9 are the only Neon Numbers
Enter the lower range
0
Enter the Upper range
5000
Neon Numbers:0 1 9
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[])
{
int upperRange=0,lowerRange=0,sum=0,squaredNumber=0,r=0,i=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the lower range");
lowerRange=sc.nextInt();
System.out.println("Enter the Upper range");
upperRange=sc.nextInt();
System.out.print("Neon Numbers:");
for(i=lowerRange;i<=upperRange;i++)
{
squaredNumber=i*i;
sum=0;
while(squaredNumber!=0)//Loop to find the sum of digits.
{
r=squaredNumber%10;
sum=sum+r;
squaredNumber=squaredNumber/10;
}
if(sum==i)
{
System.out.print(i+" ");
}
}
}
}
Python
lowerRange=int(input("Enter lower value:"))
upperRange=int(input("Enter upper value:"))
print("Neon Numbers:")
for i in range(lowerRange,upperRange):
squareOfNumber=i**2
sumOfDigits=0
while(squareOfNumber>0):
rem=squareOfNumber%10
sumOfDigits=sumOfDigits+rem
squareOfNumber=squareOfNumber//10
if(sumOfDigits==i):
print(i, end=" ")