Adam Numbers

Given a starting number and the ending number the task is to find the all the Adam Number present in that given range and also to display it’s frequency.

Adam Number is a number whose square of the number and square of it’s reverse are reverse to each other.

Example 1: 12. Here 122 = 144 and 212 = 441. We observe that the square of 12 and the square of it’s reverse i.e. 21 are reverse of each other. Thus 12 is an Adam Number.

Java
import java.util.*;
public class AdamNumberRange
{
    public static void main(String args[])
    {
        int start=0,end=0,r=0,rev=0,temp=0,frequency=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("Adam Numbers in the given range are:-");
        for(int i=start;i<=end;i++)
        {
            temp=i;
            while(temp>0)
            {
                r=temp%10;
                rev=(rev*10)+r;
                temp=temp/10;
            } 
            temp=rev*rev;
            rev=0;
            while(temp>0)
            {
                r=temp%10;
                rev=(rev*10)+r;
                temp=temp/10;
            }
            if(rev==(i*i))
            {
                System.out.println(i);
                frequency++;
            }
            rev=0;
        }
        System.out.println("Frequency: "+frequency);
    }
}
Java