# Automorphic Number Java Program

#
**What Is an Automorphic Number?**

**A number is said to be an Automorphic number ****if and only if the square of the given number ends with the same number
itself.**

**For example:- The numbers ****25 and 76** are automorphic numbers because their square is
**625** and
**5776**, respectively and the last **two** digits of the square represent the
number itself. Some other automorphic numbers are **5, 6, 36, 890625**,
etc.

**Checkout:-
Neon Number In Java - Solved Program**

**Checkout:-
Spy Number In Java - Solved Program**

**Checkout:-
Sort Matrix in Ascending Order Java**

** Checkout:-
Sorting Rows of Matrix in Descending Order Java**

# In this tutorial, we will write a program to print the Automorphic number in java using while loop.

**Automorphic Number in Java Algorithm:-**

**Step 1:** Input a number (num).

**Step 2:** Square the number (num) and store it in (sqr).

**Step 3:** Count the number of digits of (num).

**Step 4: ** Compare the last digits of (num) and (sqr).

**Step 5: **If the last digit(s) are equal to the number
entered, then the number is Automorphic else not.

For example:-

25² = 625

The number 25 is an automorphic number because the square of 25 i.e. 625 ends with 25 factorial of each digit represent the number itself.

Basically, the logic we have implemented in this program is pretty
simple. You can take a look at the code written below and understand the
logic.

## Automorphic Number In Java using While Loop

import java.util.*; class Automorphic_Nmber { public static void main() { Scanner sc=new Scanner(System.in); int num; System.out.println("Enter a number:"); num=sc.nextInt(); int sqr = num * num; while (num > 0)

`{ if (num % 10 != sqr % 10)`

//comparing the digits until the number becomes 0

`{ System.out.println("It is not an Automorphic Number"); } num = num/10;`

//find the remainder (last digit) of variable num and sqr and compare them

`sqr = sqr/10; } System.out.println("It is an Automorphic Number"); } }`

//reduce num and square by dividing them by 10

** Enter a number:
76
It is an Automorphic Number**

## 0 Comments

Just write down your question to get the answer...