How do you compare a palindromic word to one of the newly formed words of an anagram?
And how do you grab one of the newly formed words for it to be compared to the input word?
This is my code:
public class SampleCode2 {
public static boolean isPalindromic(String word, String mark) {
if (word.length() == 0) {
}
for (int i = 0; i < word.length(); i++) {
String newMark = mark + word.charAt(i);
String newLetters = word.substring(0, i) +
word.substring(i + 1);
}
String ifPalindrome = ""; //will store here the reversed string
String original = word; //will store here the original input word
//to reverse the string
for (int i = word.length() - 1; i >= 0; i--) {
ifPalindrome += word.charAt(i);
}
//to compare the reversed string to the anagram
if (word.equals(ifPalindrome)) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
boolean check = isPalindromic("mmaad", "");
System.out.println(check);
}
}
It's not yet done because the permutation and comparison won't work. The output is displaying false
, I need it to be true
because the anagram of MMAAD
is madam
. And I have to check if madam
is indeed a palindrome of mmaad
.