Automorphic Number – Java Program

Write a program in Java to input a number and check whether it is Automorphic or not.
An automorphic number is an integer whose square ends with the given integer, as
(25)^2 = 625, and
(76)^2 = 5776.

import java.util.Scanner;
class Automorphic
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number");
        int n=sc.nextInt();
        
        int l = (""+n).length();
        int sq=n*n;
        int end = sq % (int)Math.pow(10,l);
        
        if(n==end)
            System.out.println("It is Automorphic Number");
        else
            System.out.println("It is not Automorphic Number");
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *