Automorphic Number in JAVA

Automorphic Number


Program to check a number is Automorphic or Not.
A Number is said to be Automorphic if the last digit of its square is same as the Number.

Example : Input: 25, Square= 625
Output : 25 is automorphic number.

Program below:-


import java.io.*;
import java.util.*;
class Automorphic
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
                int n, sq, copy, c=0;
                System.out.println("Enter Number");
                n= in.nextInt();// Enter number from user
                sq=n*n;// squaring the input number
                copy=n;//assigning entered number in copy variable
                while(copy>0)
                {
                    c++;
                    copy=copy/10;//taking quotient of the number
                }
                int end= sq%(int) Math.pow(10,c);//checking the digits of the number
                if(n==end)// comparing digits with original number
                {
                    System.out.println("It is automorphic");
                }
                else
                {
                    System.out.println("It is not automorphic");
                }
            }// end of main method
        }// end of class

All the Best :)

Watch this program video : https://youtu.be/wlf7SpJhoO8

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

PalPrime Number in JAVA