package boluo;
public class Test {
public static void main(String[] args) {
// 递归求累加
System.out.println(sum(5));
// 递归求阶乘
System.out.println(mul(5));
}
public static int sum(int n) {
if (n == 1) {
return 1;
} else {
return n + sum(n - 1);
}
}
public static int mul(int n) {
if (n == 1) {
return 1;
} else {
return n * mul(n - 1);
}
}
}
递归求阶乘
于 2019-09-14 22:22:11 首次发布