SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Java program automorphic number
Java program automorphic number
Output:
Enter the number to check whether automorphic number or not:
76
Automorphic number
Implementation:
/* An automorphic number is a number whose square ends in the same digits as the number itself. For example: 5 * 5 = 25 6 * 6 = 36 76 * 76 = 5776 890625 * 890625 = 793212890625 So, 5, 6, 7, 76 and 890625 are all automorphic numbers */ import java.util.*; import java.lang.*; import java.io.*; class CodeRegister { public static int checkautomorphic(int n,int square) { int flag=0; while(n!=0) { if(n%10 == square%10) { n/=10; square/=10; } else { flag=1; break; } } if(flag==1) { return 0; } else { return 1; } } public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int n; int square; System.out.println("Enter the number to check whether automorphic number or not:"); n = in.nextInt(); square = n * n; if(checkautomorphic(n,square)==1) { System.out.println("Automorphic number"); } else { System.out.println("Not an Automorphic number"); } } }
PREVIOUS
NEXT
HOME