代码参考如下;
public class test {
public static void main(String[] args) {
method fac = new method();
System.out.println(fac.factorial(3));
}
}
class method {
public int factorial(int n) {
System.out.println(n);
if (n == 1) {
return 1;
}
else {
return factorial(n-1) * n;
}
}
}