Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions automorphic.java
Original file line number Diff line number Diff line change
@@ -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");
}
}