To write a program and check whether it is a automorphic number or not
Answers
Sample program to check whether the number entered by user is automorphic:
import java.util.*;
public class BrainlyPromoter
{
public static void chapter()
{
Scanner tp=new Scanner(System.in);
System.out.println("Enter a number that you want to check if its automorphic or not.");
int n=tp.nextInt();
int square=0, b=0, ct=1;
square=n*n;
int d=n;
int l=n;
while(n!=0)
{
b++;
n=n/10;
}
for(int k=1;k<=b;k++)
{
ct=ct*10;
}
int dig=square%ct;
if(dig==d)
{
System.out.println("Entered number is an automorphic number!");
}
else System.out.println("Entered number is not an automorphic number!");
}
}
Output:
Enter a number that you want to check if its automorphic.
25
Entered number is an automorphic number.