递归
最简单的递归-1-100的加法
public static int add(int n) {
if (n == 1) {
return 1;
}
return n + add(n - 1);
}
递归判断一个字符串是否为回文串——简单方法
public static boolean judge(String str) {
if (str == null || str.length() == 0 || str.length() == 1) return true;
else
return str.charAt(0) == str.charAt(str.length() - 1)
&& judge(str.substring(1, str.length() - 1));
}