递归判断是否是回文
//A1.java
public class A1 {
public static void main(String[] args) {
String str = "madam";
System.out.println(exec(str, 0));
}
public static boolean exec(String str, int i) {
if (i >= str.length() / 2) {
return true;
} else {
return str.charAt(i) == str.charAt(str.length() - 1 - i) && exec(str, i + 1);
}
}
}
public class A1 {
public static void main(String[] args) {
String str = "madam";
System.out.println(exec(str, 0));
}
public static boolean exec(String str, int i) {
if (i >= str.length() / 2) {
return true;
} else {
return str.charAt(i) == str.charAt(str.length() - 1 - i) && exec(str, i + 1);
}
}
}
运行结果:
true
浙公网安备 33010602011771号