An automorphic number is a number whose square ends in the same digits as the number itself.
For example, 6 = 36, 5 = 25, 25 = 625 are automorphic numbers.
import java.util.Scanner;
class automorphic {
public static void main(String args[]) {
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
n = sc.nextInt();
if (n*n%10==n || n*n%100==n || n*n%1000==n)
{
System.out.println(n+ " is an automorphic number ");
}
else
{
System.out.println(n+ " is not an automorphic number ");
}
}
}
For example, 6 = 36, 5 = 25, 25 = 625 are automorphic numbers.
import java.util.Scanner;
class automorphic {
public static void main(String args[]) {
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
n = sc.nextInt();
if (n*n%10==n || n*n%100==n || n*n%1000==n)
{
System.out.println(n+ " is an automorphic number ");
}
else
{
System.out.println(n+ " is not an automorphic number ");
}
}
}