|
Automorphic number are the numbers whose square "ends" in the same digits as number itself. For example, 52 = 25, 762 = 5776, and 8906252 = 793212890625, so 5, 76 and 890625 are all automorphic numbers. Here we are going to check whether the number enetered by the user is automorphic or not.
import java.math.*;
import java.util.*;
class AutomorphicNumber{
static int d=10;
public static void main(String args[]){
System.out.print("Enter any number :");
Scanner input=new Scanner(System.in);
int n=input.nextInt();
if(d>=n){
if ((n*n) % d == n){
System.out.println("Automorphic Number");
}
else{
System.out.println("Not Automorphic Number");
}
}
else if(d<=n){
d=d*10;
if ((n*n) %d==n){
System.out.println("Automorphic Number");
}
else{
System.out.println("not an automorphic number");
}
}
}
}
|
|