判断String字符串是否是回文
?
用到的方法
String.charAt(int i);// 返回指定索引处的 char
值
?
Character.isLetter(int codePoint);// 确定指定字符(Unicode 代码点)是否为字母
Character.isLetter(char c);// 确定指定字符是否为字母
?
Character.isDigit(int codePoint);// 确定指定字符(Unicode 代码点)是否为数字
Character.isDigit(char c);// 确定指定字符是否为数字
?
Character.toLowerCase(int codePoint);//将字符(Unicode 代码点)参数转换为小写
Character.toLowerCase(char c);// 将字符参数转换为小写
?
Character.toUpperCase(int codepoint);Character.toUpperCase(char c);//参见toLowerCase
?
判断回文(忽略大小写,分隔符)?
?
//A.java
public?class?A?{
????public?static?void?main(String[]?args)?{
????????String?str?=?"Madam,?I'm?Adam";
????????if?(exec(str))?{
????????????System.out.println("is?palindrome");
????????}?else?{
????????????System.out.println("not");
????????}
????}
????public?static?boolean?exec(String?str)?{
????????for?(int?i?=?0,?j?=?str.length()?-?1;?i?<?j;?i++,?j--)?{
????????????while?(!Character.isLetter(str.charAt(i)))?{
????????????????i++;
????????????}
????????????while?(!Character.isLetter(str.charAt(j)))?{
????????????????j--;
????????????}
????????????if?(Character.toLowerCase(str.charAt(i))?!=?Character.toLowerCase(str.charAt(j)))?{
????????????????return?false;
????????????}
????????}
????????return?true;
????}
}
?