Example: #1 - Check the number is a Palindrome
Check the number is a Palindrome using a divide and modulus approach
Java Input Screen
class CheckPalindrome {
public static void main(String[] args) {
int originalNumber = 12321;
int reverseNumber = 0;
int temp = originalNumber;
while (temp > 0) {
int remainder = temp % 10;
reverseNumber = (reverseNumber * 10) + remainder;
temp = temp / 10;
}
if (originalNumber == reverseNumber) {
System.out.println("The given number is Palindrome");
} else {
System.out.println("The given number is NOT a Palindrome");
}
}
}
Java Output Screen
The given number is Palindrome