57. JAVA Program to find the given number is Automorphic or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Automorphic number or not using Java.
- An Automorphic number is a number whose square ends with the number itself.
- First find the square of a number itself, after that check the condition followed by given logic then we get the Output.
Here is the code
import java.util.Scanner;
public class Auto
{
public static void main(String[] args)
{
int n, sqrnum, temp,remainder,c = 0;
System.out.print("Enter number=\n");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
temp=n;
while (temp > 0)
{
temp=temp/10;
c++;
}
sqrnum = n * n;
remainder= sqrnum%(int)Math.pow(10, c);
if(remainder==n)
{
System.out.println("Automorphic Number");
}
else
{
System.out.println("Not Automorphic Number");
}
}
}