求解:关于回文的一个问题

因为新学所以不是很懂

代码如下
package org.lh.mldn;

public class StringDemo {
public static void main(String []args) {
String st="aabbccddeeccddccbbaa";
char st1[]=st.toCharArray();
if(comp(st)){
System.out.println(st+"是回文");
}else{
System.out.println(st+"不是回文");
}
}
public static boolean comp(String s){
char st4[]=s.toCharArray();
if(s.length()==1){
return true;
}
for(int x=0;x<st4.length/2;x++){
if(st4[x]==st4[st4.length-1-x] ){
return true;

}

return false;
}
return false;
}
}

aabbccddeeccddccbbaa 这明显不是一个回文字符串
想知道我的程序哪里有问题

不好意思,反了个低级错误,有错函数了,呵呵。还好测试了一下
[code="java"]
//判断字符串是否是回文字符串
public static boolean comp(String s) {
int length = s.length();
if (length == 1) {
return true;
} else {
int times=length/2;
for (int i = 0; i < times; ++i) {
if (s.charAt(i) == s.charAt(--length)) {
continue;
}else{
return false;
}
}
return true;
}

}
[/code]

[quote]for(int x=0;x<st4.length/2;x++){
if(st4[x]==st4[st4.length-1-x] ){
return true;

}
return false;
}
[/quote]

错误太明显了吧,只要有一个相同就返回true 了 !

推荐写法,注意代码的书写规范性
[code="java"]
//判断字符串是否是回文字符串
public static boolean comp(String s) {
int length = s.length();
if (length == 1) {
return true;
} else {
int times=length/2;
for (int i = 0; i < times; ++i) {
if (s.indexOf(i) == s.indexOf(--length)) {
continue;
}else{
return false;
}
}
return true;
}

}
[/code]