import java.util.Scanner;
public class C201_07_06计算阶乘 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.printf("输入一个数:");
int num = scan.nextInt();
int result = factorial(num);
System.out.println(result);
}
/**
* 计算阶乘
* @param num 输入的数
* @return 返回阶乘结果
*/
private static int factorial(int num) {
int result = 1;
if (num == 0) {
return 1;
}
return num*factorial(num-1);
/*for (int i = 1; i <= num; i++) {
result *=i;
}//普通for循环写
return result;*/
}
}
5!=120
6!=720