An Automorphic number is a number whose square ends with the same digits as the original number.
E.g – 25, 76, 376 etc.
Steps to Check Automorphic Number :
Program:- Take a number as input (num).
- Square the number (sqr).
- Count the number of digits of (num) using while loop (c).
- Compare the last (c) digits of (sqr) with the (num).
- If they are equal then the number is Automorphic else not.
import java.util.*;
public class Automorphic_imp_fun
{
public void fun(int n)
{
int c=0,sqr=1,temp,lastSquareDigits;
sqr = n*n;
temp=n;
while(temp>0)
{
c++;
temp=temp/10;
}
lastSquareDigits=(int)(sqr%(Math.pow(10,c)));
if(n == lastSquareDigits)
{
System.out.println("Automorphic number");
}
else
System.out.println("Not an Automorphic number");
}
public static void main(String args[])
{
int no;
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
no= sc.nextInt();
Automorphic_imp_fun obj=new Automorphic_imp_fun ();
obj.fun(no);
}
}
Output:
Enter a number
5
Automorphic number
Enter a number
12
Not an Automorphic number