how can i check a given string to form a palindrome or not
for(i=0;i<str.length();i++)
{
if(str.charAt(i)==str1.charAt(i)
}
}

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.

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");

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

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.

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?

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

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

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

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

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

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

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

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

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;i<charArray.length;i++)
        {
            char c = charArray[i];

            System.out.println("Hi"+c);
            int count = 0;

            for(int x=0;x< charArray.length ;x++)
            {
                if(charArray[x]==c) 
                {
                    count++;
                }
            }

            if (count%2!=0)
            {
                count1++;
            }

            if(count1>1)
            {
                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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.