您的位置:首页 > 其它

回文原来是这样的

2010-02-05 11:07 183 查看
import java.util.*;
public class HuiWen {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("please input a String:");
String st = in.nextLine();
String s = st.toLowerCase();
int i = 0;
int j = s.length() - 1;
boolean t = true;
char first = s.charAt(i);
char last = s.charAt(j);
for(;i<j;){
while(!(first >= 'a' && first <= 'z')){
i++;
first = s.charAt(i);
}
while(!(last >= 'a' && last <='z')){
j--;
last = s.charAt(j);
}
if(i >= j){
break;
}
if(first == last){
i++;
j--;
first = s.charAt(i);
last = s.charAt(j);
}
else{
t = false;
break;
}
}
if(t)
System.out.println(st + "是回文串");
else
System.out.println(st + "不是回文串");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: