From b55b8759b6ea166e74c22977c12d95db7ce9a40e Mon Sep 17 00:00:00 2001 From: deepak453 <57010430+deepak453@users.noreply.github.com> Date: Fri, 25 Oct 2019 22:21:55 +0530 Subject: [PATCH] Create automorphic.java --- automorphic.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 automorphic.java diff --git a/automorphic.java b/automorphic.java new file mode 100644 index 0000000..149d2f8 --- /dev/null +++ b/automorphic.java @@ -0,0 +1,31 @@ +// Java program to check if a number is Authomorphic +class Test { + // Function to check Automorphic number + static boolean isAutomorphic(int N) + { + // Store the square + int sq = N * N; + + // Start Comparing digits + while (N > 0) { + // Return false, if any digit of N doesn't + // match with its square's digits from last + if (N % 10 != sq % 10) + return false; + + // Reduce N and square + N /= 10; + sq /= 10; + } + + return true; + } + + // Driver method + public static void main(String[] args) + { + int N = 5; + + System.out.println(isAutomorphic(N) ? "Automorphic" : "Not Automorphic"); + } +}