/** * An example program that Determine Automorphic number program in java using while loop */ public class ExampleProgram { public static void main(String[] args) { System.out.println(376 + " is automorphic? : " + isaAtomorphic(376)); System.out.println(25 + " is automorphic? : " + isaAtomorphic(25)); System.out.println(123 + " is automorphic? : " + isaAtomorphic(123)); System.out.println(200 + " is automorphic? : " + isaAtomorphic(200)); } public static boolean isaAtomorphic(int n) { int square = n * n; while (n > 0) { int d1 = n % 10; int d2 = square % 10; if (d1 != d2) { return false; } n = n / 10; square = square / 10; } return true; } }
And we get results below:
376 is automorphic? : true 25 is automorphic? : true 123 is automorphic? : false 200 is automorphic? : false