判断回文(忽略大小写,分隔符)
//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;
}
}
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;
}
}
浙公网安备 33010602011771号