English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2007-04-24 15:34:42 · 3 answers · asked by freedom_2k6 1 in Computers & Internet Programming & Design

In java prigramming ....
It cannot be assigned.... why..

StringBuffer g=s.ToString();//error

2007-04-25 03:23:14 · update #1

3 answers

Oh, come on... Don't tell me you're in a sugar coma...

Take half of a string (if it's odd number length, do nearest integer)

Copy the string, and reverse it, then attach to the original. Now you have palindrome, right?

Compare it against the original FULL string. Do they match? Yes, original is palindrome. No, then no.

2007-04-24 15:50:44 · answer #1 · answered by Kasey C 7 · 0 0

I know Stringbuffer exists in Java only.
Create a String Object and accept the String say "MADAM" for it.
Now create an obbject of stringbuffer class and assign the same string object to it.

now, stingbuffer object has reverese function call it & compare it with existing string

thats it.

String S1="MADAM";
String Buffer S2=S1.ToString();
if S1==S2.reverse()
System.out.println("PALINDROME");
else
System.out.println("NOT A PALINDROME");

2007-04-25 06:03:58 · answer #2 · answered by Ravi Nanjunda Rao 3 · 0 0

What language?

In general, you just need to find the midpoint of the string and compare the characters forward and backward from the midpoint. If there are an even number of characters, you compare the two at the middle first. If odd, then you compare starting at the characters bracketing the middle character.

2007-04-24 22:52:57 · answer #3 · answered by Amanda H 6 · 0 0

fedest.com, questions and answers