Automorphic Number in Java

Automorphic numbers are those numbers that when squared have the exact same end digits as the number.

For example, the number 376.

Now the square of the number, 376 is 141376. The last three digits of the square are exactly like the number themselves. Hence, 376 is an Automorphic Number.

However, let the number is 45.

Now the square of the number, 45 is 2025. The last two digits of the square (25) are not same as the number 45. Hence, 45 is NOT an Automorphic Number.

Below is a program that inputs a number, and checks whether it is an automorphic number or not.

Program to Check Automorphic Number in Java

Output:

Enter a Number: 376
The number is an Automorpic number

The program runs a while loop in which the unit’s digit of the number and the square is compared (number % 10), until all the digits in the number are exhausted. The unit’s digit of the number and the square are removed in every iterance.

Leave a Comment

Your email address will not be published. Required fields are marked *