| | |
check whether a palindrome can be formed from a given stirng
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Assuming your palindrome logic ignores case, here is one solution:
java Syntax (Toggle Plain Text)
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");
I don't accept change; I don't deserve to live.
•
•
Join Date: Feb 2007
Posts: 20
Reputation:
Solved Threads: 0
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
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
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.
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.
I don't accept change; I don't deserve to live.
•
•
•
•
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
"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?
Last edited by stultuske; May 21st, 2007 at 5:11 am.
•
•
Join Date: Feb 2007
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
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?
![]() |
Similar Threads
- Starting Python (Python)
- Can anyone figure out what is wrong in my program? (C++)
- need help in programing a matrix calculator (C++)
- Trying To Create a Palindrome Programme (Pascal and Delphi)
- Finding length (Java)
- my first recursion program... :/ (C)
- I cant correct these two errors (C++)
- Stack Queue Fstream (C++)
Other Threads in the Java Forum
- Previous Thread: chats and graphs
- Next Thread: Quick question about "getLocation()"
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working







