A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.
To check whether a word is a palindrome I get th
Another way is using char Array
public class Palindrome {
public static void main(String[] args) {
String str = "madam";
if(isPalindrome(str)) {
System.out.println("Palindrome");
} else {
System.out.println("Not a Palindrome");
}
}
private static boolean isPalindrome(String str) {
// Convert String to char array
char[] charArray = str.toCharArray();
for(int i=0; i < str.length(); i++) {
if(charArray[i] != charArray[(str.length()-1) - i]) {
return false;
}
}
return true;
}
}