Given a starting number and the ending number the task is to find the all the Neon Number present in that given range and also to display it’s frequency.
Neon Number is a number whose sum of digits of it’s square is equal to the original number.
Example 1: 9. 92 = 81. 8+1=9. We observe that the sum of digits of the square of original number is equal to the original number. Hence it is a Neon Number.
Example 2: 11. 112 = 121. 1+2+1 = 4. Here the sum of digits of the square of original number is not equal to the original number. Hence it is not a Neon Number.
Java
import java.util.*;
public class NeonNumberRange
{
public static void main(String args[])
{
int start=0,end=0,temp=0,frequency=0,r=0,s=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a starting range: ");
start=sc.nextInt();
System.out.print("Enter a ending range: ");
end=sc.nextInt();
System.out.println("Neon Numbers in the given range are:-");
for(int i=start;i<=end;i++)
{
temp=i*i;
while(temp>0)
{
r=temp%10;
s=s+r;
temp=temp/10;
}
if(s==i)
{
System.out.println(i);
frequency++;
}
s=0;
}
System.out.println("Frequency: "+frequency);
}
}Java