top of page
Writer's pictureSatyam Gupta

Automorphic Number in JAVA

Updated: Apr 30, 2019

This is a 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 : 25*25 = 625

Output : 25 is automorphic number.

Input: 6, Square : 6*6 = 36 Output : 6 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

 

Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.


All the Best :)

Keep Learning :)


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

20 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page