Automorphic Number Program in Java

Automorphic Number Program in Java
Automorphic Number Program in Java

An Automorphic number is a number whose square “ends” in the same digits as the number itself.

Examples: 5*5 = 25, 6*6 = 36, 25*25 = 625


import java.util.Scanner;

public class AutomorphicNumber
{
    public static void main(String[] args)
    {
        int n, sqrNum, temp,sqrNumRemainder,c = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter number=");
        n = sc.nextInt();
        temp=n;        
        while (temp > 0)
        {
            temp=temp/10;
            c++;
        }
        sqrNum = n * n;
        sqrNumRemainder= sqrNum%(int)Math.pow(10, c);
        if(sqrNumRemainder==n)
        {
            System.out.println("Automorphic Number");
        }
        else
        {
            System.out.println("Not Automorphic Number");
        }
        
        
    }
}

Output:

Enter number=25
Automorphic Number
b. tech. bca icse java java tutorials learn java mca programs

Frequently Asked Questions

An Automorphic number is a number whose square “ends” in the same digits as the number itself. Examples: 5*5 = 25, 6*6 = 36, 25*25 = 625
An Automorphic number is a number whose square “ends” in the same digits as the number itself. Examples: 5*5 = 25, 6*6 = 36, 25*25 = 625
Recent Posts