A number is said to be adam number if a number is squared and reversed and then its root is found out and again reversed and hence if the number obtained is same as the initial number then its is called an adam number.
Adam numbers up to 1000 are: 0, 1, 2, 3, 11, 12, 13, 21, 22, 31, 101, 102, 103, 111, 112 , 113, 121, 122, 201, 202, 211, 212, 221, 301, 311.

Click here for java videos

Adam number
import java.io.*; 
class Adam 
{ 
    static int rev(int num) 
    { 
        int rev=0; 
        while(num!=0) 
        { 
            int rem=num%10; 
            rev=rev*10+rem; 
            num=num/10; 
        } 
        return rev; 
    } 

    static int sq(int a) 
    { 
        int sq_a=a*a; 
        return sq_a; 
    } 

    static boolean isAdam(int b) 
    {
        int b_sq=sq(b); //square of real num 
        int rev_b=rev(b); //reverse of real num 
        int sq_rev=sq(rev_b); //square of reversed num 
        int rev_sq=rev(sq_rev); //reverse of the square of the reversed num   
        if(b_sq==rev_sq) 
        { 
            return true; 
        } 
        else 
        { 
            return false; 
        } 
    } 

    public static void main()throws IOException 
    { 
        BufferedReader br=new BufferedReader(new  
                InputStreamReader(System.in)); 
        System.out.println("ENTER THE RANGE"); 
        System.out.println("ENTER LOWER LIMIT"); 
        int m=Integer.parseInt(br.readLine()); 
        System.out.println("ENTER UPPER LIMIT"); 
        int n=Integer.parseInt(br.readLine()); 
        int freq=0; 
        if(m<n) 
        { 
            System.out.println("THE ADAM INTEGERS ARE:");
            for(int i=m;i<=n;i++) 
            { 
                if(isAdam(i)==true) 
                { 
                    System.out.print(i+"\t"); 
                    freq++; 
                } 
            } 
            System.out.println(); 
            System.out.println("FREQUENCY OF ADAM INTEGERS IS: "+freq);  } 
        else 
        { 
            System.out.println("INVALID RANGE"); 
        } 
    } 
} 

Output:
ENTER THE RANGE
ENTER LOWER LIMIT
100
ENTER UPPER LIMIT
200
THE ADAM INTEGERS ARE:
101 102 103 111 112 113 121 122
FREQUENCY OF ADAM INTEGERS IS: 8

Keith Number

LEAVE A REPLY

Please enter your comment!
Please enter your name here