打印问题:
public class Print {
public static void main(String[] args) {
test(4);
System.out.println();
test1(4);
}
//静态方法
public static void test(int value) {
if (value > 2) {
test(value - 1);
}
System.out.println("value = " + value);
}
public static void test1(int n) {
if (n > 2) {
test1(n - 1);
} else{
System.out.println("value = " + n);
}
}
}
阶层问题:
public class Factorial {
public static void main(String[] args) {
int a = factorial(3);
System.out.println(a);
}
//阶乘factorial问题
public static int factorial(int n) {
if (n == 1) {
return 1;
} else {
return factorial(n - 1) * n;
}
}
}