此题考察递归的应用 代码如下:
static int sum = 0;
public static boolean add(int n) {
sum += n;
return n == 1 || add(--n);
}
public static boolean bool(int n) {
return n < 1 || add(n);
}
public static void main(String[] args) {
bool(100);
System.out.println(sum);
}
关键是递归如何退出 !