Automorphic Number Check in Java: Explanation & Practice
Check if a number is automorphic
Problem summary
An automorphic number's square ends with the number itself (e.g., 25² = 625). Check if the given number is automorphic.
Starter code
public class Main {
public static void main(String[] args) {
int number = 25; // Test case 1
// Check if automorphic
// Print: Is automorphic: <true/false>
}
}Expected output and test cases
- 25² = 625 ends with 25
Is automorphic: true
- 76² = 5776 ends with 76
Is automorphic: true
- 15² = 225 doesn't end with 15
Is automorphic: false
Hints
- Calculate the square
- Find how many digits in original number
- Use modulus to get last n digits of square
Related Core Java Basics exercises
- Practice Happy Number Check in Java
- Practice Strong Number Check in Java
- Practice Binary to Decimal in Java
Practice all Core Java Basics exercises · Run this idea in the Java compiler