算法学习——递归之阶乘
算法描述
阶乘
算法思路
n = n *(n-1)
算法实现
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.close();
int result = jiechen(n);
System.out.println("阶乘的结果为"+result);
}
public static int jiechen(int n){
if(n!=1){
return n*jiechen(n-1);
}else{
return n;
}
}