Automorphic Number
✹An Automorphic Number is a number whose square ends in the same digits as the number itself.
import java.util.*;
class
Automorphic_Number
{
public static void main(String[] args)
{
int n,sq,d=0,m;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number = ");
n=sc.nextInt();
m=n;
sq=n*n;
// Count Number of Digits
while(m>0)
{
d++;
m/=10;
}
// Checking the Condition
if(n==sq%(int)(Math.pow(10,d)))
System.out.println("Automorphic Number");
else
System.out.println("Not an Automorphic Number");
}
}
{
public static void main(String[] args)
{
int n,sq,d=0,m;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number = ");
n=sc.nextInt();
m=n;
sq=n*n;
// Count Number of Digits
{
d++;
m/=10;
}
// Checking the Condition
System.out.println("Automorphic Number");
else
System.out.println("Not an Automorphic Number");
}
}
No comments