public class Demo {
public static void main(String[] args) {
int result = 1;
for(int i = 5 ; i >= 1; i--){
result *= i;
}
System.out.println(result);
System.out.println("递归求阶乘结果:" + jieCheng(5));
}
//递归方法,求阶乘
public static int jieCheng(int num){
if(num == 1){
return 1;
}
return num * jieCheng(num - 1);
}
}
|
|