Assuming your palindrome logic ignores case, here is one solution:
String str = "AB , ba";
StringBuffer sb = new StringBuffer(str).reverse();
String strRev = sb.toString();
if(str.equalsIgnoreCase(strRev))
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
You can start off by eliminating words which don't have a repeated character. This would help you in cutting down the processing. Then with the words which have at least a pair of repeating characters, try out various combinations of the character forming the word.
For eg. if your word is "sat", you can safely eliminate it since it doesn't have a repeating character. Now if the word in consideration is "sosa", generate various combinations of the characters forming the word which has at least a pair of repeating characters. Some examples would be "sos" and "sas". Of course yo have to keep in mind that single characters are by default palindromes.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
sorry i am not trying to find the given string is palindrome or not,i am trying to find from a given string is it possible to form a palindrome or not?
suppose u input "oppa"
from this string it is possible to from a palindrome "pop"
but if u input a string"opai"
it is not possible to form a palindrome.that is what i want please if u know tell me
what exactly are you trying to do???
"pop" is in no way a palindrome to "oppa".
a palindrome to "oppa" would be "appo".
you are here asking, is it possible to find a palindrome for "opai" with boolean 'false' as return.
well... the palindrome to "opai" is "iapo".
so, if I'm not mistaking, you're trying to find a word that is a palindrome and that can be formed with the letters used in the original (input)String?
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
well... the palindrome to "opai" is "iapo".
brrrr... by my last post you can propably see I didn't sleep to well ... :)
opai is no palindrome, excuse me for the mistake
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
> i am not trying to find i am trying to form a palindrome fron the letters of the given string
Use the approach suggested by me in my previous post.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
hey i think what you can do is you find the frequency of characters in a word
Like ""madam" is having 2 m and 2 "a" and 1"d" so u can make pallindronme for it
Its just a logic that u can think abt...Hope it will help u in 1 way or another
staneja
Junior Poster in Training
64 posts since Dec 2006
Reputation Points: 10
Solved Threads: 2
Oh........If you can find the frequencey of character than do one thing
Pick the words with even frequency and 1 word with odd frequency
Like i netered word barbara
Now whats frequent of
a=3
b=2
r=2
SO either you make
bab .....rar.....rababar....rbabr
did you getting me or not
staneja
Junior Poster in Training
64 posts since Dec 2006
Reputation Points: 10
Solved Threads: 2
Welcome to DaniWeb. But...
1. Always post code in code tags
2. We don't do people's homework for them.
3. This post is from 2007. You are certainly not going to help the original poster.
To avoid a difficult conversation with a DaniWeb administrator, check out the Member rules before your next post...
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
JamesCherrill
Posting Genius
6,370 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073