|
there are 2 approaches, 1 would be to gnerate every possible combination of letters, and write an isPalindrome(String s) method, this is very expensive and not efficient in the slightest, so i would suggest you try the following: check the word for each letter contained in the word and get a count of the number of times that letter appears, if the letter has a count greater than 2, then the letter can be used in a palindrome, along with 1 letter which has a count of 1. The method which constructs the palindrome would simply place each even letter then the odd letter, and reverse the order of the even letters. This also depends on if you are using a database of real words which must exist, or if the fact that it is a palidrome is enough.
Hopefully this is enough to get you going, this will also work for any length of word. Using your examples: opap: o = 1 p = 2 a = 1 so your output could be: pap, or pop
another: qwerherwnw q = 1 w = 3 e = e r = 2 h = 1 j = 1 n = 1 the output could be: wreherw, rewnwer, erwwwre, etc
|