Definition: A number is called an Automorphic number if and only if its square ends in the same digits as the number itself.
This is what I wrote for the code:
import java.util.*;
public class AutomorphicOrNot
{
    public static void main(String [] args)
    {
        System.out.println("Enter a number:");
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n;
        int i;
        int t=x^2;
        
        for(i=1;i<t;i++)
        {
            t=t%10;
        }
        n=i;
        if((t%(Math.pow(10,n)))==x)
        {
           System.out.println("It is an automorphic number");
        }
        else
        {
           System.out.println("It is not an automorphic number");
        }
    }
}
Mathematically, the code looks correct to me. However, I got the wrong output for the same. For example, when I enter 25, I get: It is not an automorphic number. Similarly there is a discrepancy for other entries as well.
I have just recently begun to learn coding. I hope you could help me to figure out the error. Thank you.
 
    