Home » Adam Number in Java

Adam Number in Java

by Online Tutorials Library

Adam Number in Java

In this section, we will learn what is an Adam number and also create Java programs to check if the given number is Adam or not. The Adam number program frequently asked in Java coding tests and academics.

Adam Number

A number is called an Adam number if the square of a number and the square of its reverse are reverse to each other. Let’s understand it through an example.

Adam Number Example

Consider a number (N) 12 and check it is an Adam number or not.

Square of the number (N) = 144

The reverse of the number (N) = 21

Square of the reverse of the number (N) = 441

We observe that the square of 12 and the square of its reverse i.e. 21 are reverse of each other. Hence, 12 is an Adam number.

Some other Adam numbers are 0, 1, 2, 3, 11, 12, 13, 21, 22, 31, 101, 102, 103, 111, etc.

Steps to Find Adam Number

  1. Read or initialize a number N.
  2. Find the square of the number.
  3. Find the reverse of the square.
  4. Reverse the number N.
  5. Find the square of the reversed number.
  6. If the reverse of the square of the number is equal to the square of the reverse of the number, the number is an Adam number, else not.

Let’s implement the above steps in a Java program.

Adam Number Java Program

AdamNumberExample1.java

Output 1:

Enter the number: 301  301 is an Adam number.  

Output 2:

Enter the number: 276  276 is not an Adam number.  

Let’s create another Java program and find all the prime Adam numbers between the given range.

PrimeAdamExample.java

Output:

Enter the lower limit: 0  Enter the upper limit: 1000  The prime Adam numbers are:  2 3 11 13 31 101 103 113 211 311   Frequency of Adam number is: 10  

You may also like