Kodekraftt
/Blog
/Automorphic Number In Java Definition Explanation And Step By Step Program
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

Automorphic Number in Java: Definition, Explanation, and Step-by-Step Program

A clear and detailed guide on Automorphic Numbers in Java, including definition, examples, logic breakdown, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Automorphic Number in Java

An Automorphic Number is a number whose square ends with the number itself. Automorphic numbers are commonly asked in Java programming assignments, school exams, and coding interviews because they test logical reasoning and understanding of number manipulation.

What Is an Automorphic Number?

A number n is considered automorphic if:

The last digits of n² match the digits of n

Examples

  • 5 → 25 (ends with 5)
  • 6 → 36 (ends with 6)
  • 25 → 625 (ends with 25)
  • 76 → 5776 (ends with 76)

Therefore, numbers like 5, 6, 25, 76, 376, 625 are automorphic.

How Do We Check Automorphic Numbers in Java?

The logic is straightforward:

  1. Compute the square of the number
  2. Count the digits of the original number
  3. Extract the last digits of the square equal to the number of digits of the original number
  4. Compare both values

Java Program to Check Automorphic Number


import java.util.*;

public class AutomorphicNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        int square = num * num;
        int temp = num;

        int digits = 0;
        while (temp > 0) {
            digits++;
            temp /= 10;
        }

        int lastDigits = square % (int)Math.pow(10, digits);

        if (lastDigits == num) {
            System.out.println(num + " is an Automorphic Number.");
        } else {
            System.out.println(num + " is NOT an Automorphic Number.");
        }
    }
}

  

Example Explanation

If the input is 76:

  • 76² = 5776
  • Last two digits = 76
  • Since both match, 76 is an Automorphic Number

Common Automorphic Numbers

  • 1
  • 5
  • 6
  • 25
  • 76
  • 376
  • 625

Practice Challenge

Write a Java program that prints all automorphic numbers between 1 and 10,000. Use the same logic as above but apply it inside a loop. This will help reinforce the concept and improve your understanding of number-based Java programs.

You might also like

Disarium Number in Java: Definition, Examples, and Complete Program

A detailed explanation of Disarium Numbers in Java with definition, examples, step-by-step logic, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Fascinating Number in Java with Explanation, Definition, Examples, and Program

A Fascinating Number is a number which, when multiplied by 2 and 3 and then concatenated with itself, forms a string that contains all digits from 1 to 9 exactly once.

Check Perfect Square in Java Without Using Math.sqrt() – Explanation, Logic, Examples, and Program

Learn how to check whether a number is a Perfect Square in Java without using Math.sqrt(). This guide explains the logic, provides examples, and includes an efficient program using iterative checking.

Spy Number in Java — Definition, Logic, Examples, and Program

Learn what a Spy Number is in Java with clear explanations and examples. This blog covers the definition, logic, step-by-step approach, and a clean Java program to check whether a number is a Spy Number. Includes practice challenges to improve your number theory skills.

Happy Number in Java

Learn what a Happy Number is and how to check whether a number is happy or not in Java. This guide explains the concept, algorithm, working process, dry run, and provides multiple Java programs for beginners.

Sad Number in Java — Definition, Explanation, Examples, and Program

Learn what a Sad Number is in Java with clear explanation and logic. This blog covers the definition of a Sad Number, how it differs from a Happy Number, examples, and a complete Java program. Includes practice challenges to strengthen your number theory concepts.