954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

check whether a palindrome can be formed from a given stirng

how can i check a given string to form a palindrome or not
for(i=0;i

pavani2006
Newbie Poster
20 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

Hmm whats str1?
You have to compare the first letter and the last letter, then the second letter and the last but one letter and so on. So...think how we could go about doing that.

jetru
Light Poster
27 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

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
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

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

pavani2006
Newbie Poster
20 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 
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,119 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 
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,119 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 
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?


i am not trying to find i am trying to form a palindrome fron the letters of the given string

pavani2006
Newbie Poster
20 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

> 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
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

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
 
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


i can find the frequency of the letters but the problem is to from the palindrome from the characters.i am not getting to do it.can u help

pavani2006
Newbie Poster
20 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
 
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

[quote]i know i have combine the even and odd charaCTERS but i dont knoew how to combine?

pavani2006
Newbie Poster
20 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] array = {"1122344"};
boolean result = true;
int count1=0;

char[] charArray=array[0].toCharArray();
for(int i=0;i1)
{
result=false;
break;
}


}
System.out.println("Is it possible to form a palindrom using the given number a Palindrome:"+result);
}

}

HOPE THIS WILL HELP YOU - JAMSHEER

P.J.Ali
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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
Moderator
6,339 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,070
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You