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");
    }
}

1 thought on “Automorphic Number – Java Program”

  1. EASIER WAY TO DO IT!!!!!!!!!!
    import java.util.*;
    class Automorphic
    {
    public static void main()
    {
    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter the number”);
    int n=sc.nextInt();
    int t1,t2;
    t1= n%10;
    t2=(n*n)%10;
    if(t1==t2)
    System.out.println(“It is Automorphic Number”);
    else
    System.out.println(“It is not an Automorphic Number”);
    }
    }

Leave a Comment

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