import java.util.Scanner;
public class AutomorphicNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
int square = num * num;
String str1 = Integer.toString(num);
String str2 = Integer.toString(square);
if (str2.endsWith(str1)) {
System.out.println(num + " is an automorphic number.");
} else {
System.out.println(num + " is not an automorphic number.");
}
scanner.close();
}
}
Enter a number: 5
5 is an automorphic number.
Enter a number: 23
23 is not an automorphic number.
Scanner
class. Then we calculate the square of the number and convert both the number and its square to strings using the toString()
method.