Java Program to Check Palindrome
A palindrome is a word, number, or string that reads the same forward and backward.
Examples:
madam
level
121
🔹 Using String Reverse Logic
public class PalindromeCheck {
public static void main(String[] args) {
String original = "madam";
String reversed = "";
for(int i = original.length() - 1; i >= 0; i--) {
reversed = reversed + original.charAt(i);
}
if(original.equals(reversed)) {
System.out.println("Palindrome");
} else {
System.out.println("Not a Palindrome");
}
}
}
🔹 Using Two-Pointer Approach (Efficient Method)
public class PalindromeCheck {
public static void main(String[] args) {
String str = "level";
boolean isPalindrome = true;
int start = 0;
int end = str.length() - 1;
while(start < end) {
if(str.charAt(start) != str.charAt(end)) {
isPalindrome = false;
break;
}
start++;
end--;
}
if(isPalindrome)
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
}
}
🔹 Output
Palindrome
✅ Conclusion
Checking a palindrome is a common Java interview question that helps evaluate string handling and logical thinking skills.
🔥 Promotional Content
Learn Java coding, real-time problem solving, and backend development with the Best Java Real Time Projects Online Training in 2026 by ashok it.

