In this Java tutorial section, you will learn how to check whether the number entered by the user is automorphic number or not.
In this Java tutorial section, you will learn how to check whether the number entered by the user is automorphic number or not.Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number as the square of 5 is 25 and its square consists of number 5 in the end. Similarly 6 is an automorphic number as the square of 6 is 36 and its square consists of number 6 at the end. Here we are going to check whether the number entered by the user is automorphic or not.
Here is the code:
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"); } } } }Output
Enter any number :56 Not an automorphic number