- import java.util.Scanner;
- class Recursion
- {
- public static int factorial(int n)
- {
- if(n==1)
- {
- return 1;
- }
- int temp = n*factorial(n-1);
- return temp;
- }
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个正整数:");
- int positive = sc.nextInt();
- int result = factorial(positive);
- System.out.println(result);
- }
- }
复制代码
|
|