Automorphic Number in Java
Check Whether Or Not the Number is an Automorphic Number in Java
Given an integer input, the Objective is to check whether the square of the number ends with the same number or not. Therefore, we’ll write a code to Check Whether or Not the Number is an Automorphic Number in Java Language.
Example Input : 5 Output : Yes, it's an Automorphic Number

Check Whether or Not the Number is an Automorphic Number in Java
Given an integer input, the objective is to check whether or not the Number is an automorphic number or not. To do so we’ll check whether the square if the number ends with the number itself of not. For a number to be Automorphic, it’s square has to end with the number itself. Let’s implement the above mentioned logic in Java Language.
Automorphic Number
A Number that when squared ends with the number itself is known as the Automorphic Number.
Let's try and understand the concept of Automorphic Number,
Example Input : 5 Output : 25 Explanation : Number = 5 when squared you get 25 as 25 ends with 5From the above example, we prove that the number 5 is an Automorphic Number.
Automorphic Number in C Programming
Example:
5 =(5)2 = 25 6 = (6)2 = 36 25 = (25)2 = 625 76=(76)2 = 5776 376 = (376)2 = 141376 890625 = (890625)2 = 793212890625
These numbers are the automorphic numbers.

Java Code
Run
public class Main { public static void main(String[] args) { int n = 376, sq = n * n ; if(isAutomorphic(n) == 1) System.out.println("Num: "+ n + ", Square: " + sq + " - is Automorphic"); else System.out.println("Num: "+ n + ", Square: " + sq + " - is not Automorphic"); } static int isAutomorphic(int n){ int square = n * n; while(n != 0) { // means not automorphic number if(n % 10 != square % 10){ return 0; } // reduce down numbers n /= 10; square /= 10; } // if reaches here means automorphic number return 1; } }
Output
Num: 376, Square: 141376 - is Automorphic
Some other methods to solve the problem :
Method 1 :
Run
public class Main { public static void main(String[] args) { int x=5; int y=x*x; if(y%10==x%10) System.out.println("automorphic"); else System.out.println("not"); } }
Output :
automorphic
Method 2 :
Run
class HelloWorld { public static void main(String[] args) { int num=10; int sqt=num*num; int count=0; int temp=num; while(temp!=0) { temp=temp/10; count++; } temp=sqt; int rem=0,rev=0; for(int i=0;i< count;i++) { rem=temp%10; rev=rev*10+rem; temp=temp/10; } if(rev==num) System.out.println("Automorphic Number"); else System.out.println("No Automorphic Number"); } }
Output :
No Automorphic Number
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
package All_java;
public class Main {
public static void main(String[] a) {
System.out.println(ab(7));
}
static boolean ab(int x) {
return ((x*x) % 10) == (x % 10);
}
}