An Automorphic number is a number whose square ends with the same digits as the original number.
E.g – 25, 76, 376 etc.
import java.util.*;
public class Automorphic_pure_fun
{
public int fun(int n)
{
int c=0,sqr=1,lastSquareDigits;
sqr = n*n;
while(n>0)
{
c++;
n=n/10;
}
lastSquareDigits=(int)(sqr%(Math.pow(10,c)));
return(lastSquareDigits);
}
public static void main(String args[])
{
int no,p,temp;
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
no=sc.nextInt();
temp=no;
Automorphic_pure_fun obj=new Automorphic_pure_fun ();
p=obj.fun(no);
if(p == temp)
{
System.out.println("Automorphic number");
}
else
System.out.println("Not an Automorphic number");
}
}
Output:
Enter a number
5
Automorphic number
Enter a number
12
Not an Automorphic number