write java program to find automorphic number.
Answers
Sample program to check whether the number entered by user is automorphic:
import java.util.Scanner;
public class AutomorphicChecker
{
public static void ch()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number that you want to check if its automorphic.");
int n=sc.nextInt();
int sq=0, b=0, c=1;
sq=n*n;
int d=n;
int l=n;
while(n!=0)
{
b++;
n=n/10;
}
for(int k=1;k<=b;k++)
{
c=c*10;
}
int dig=sq%c;
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.