Palindrome Number Check in Java: Explanation & Practice
Check if a number is a palindrome
Problem summary
Write a program that checks if a number reads the same forwards and backwards.
Starter code
public class Main {
public static void main(String[] args) {
int number = 12321; // Test case 1
// Check if number is a palindrome
// Print: Is palindrome: <true/false>
}
}Expected output and test cases
- 12321 is a palindrome
Is palindrome: true
- 12345 is not a palindrome
Is palindrome: false
- 7 is a palindrome
Is palindrome: true
Hints
- Reverse the number and compare with original
- You can also compare digits from both ends
- Single digit numbers are always palindromes
Related Core Java Basics exercises
- Practice Calculate Power in Java
- Practice Calculate Factorial in Java
- Practice Greatest Common Divisor in Java
Practice all Core Java Basics exercises · Run this idea in the Java compiler