Java编程题-乘法递归

使用递归,编写一个程序:5*4*3*2*1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class HelloWorld {

public static void main(String[] args) {
int n = 5;
int result = method(n);
System.out.println(result);
}

public static int method(int n) {
if (n == 1) {
return 1;
}
return n * method(n - 1);
}

}