java面试每日一题10

时间:2023-03-09 03:36:27
java面试每日一题10

题目:利用递归方法求5!

public class Recursion {
public static void main(String args[]) throws NumberFormatException, IOException{
System.out.println("请输入一个数");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num1=Integer.parseInt(br.readLine());
int value=getRecursion(num1);
System.out.println(num1+"的阶乘是"+value);
} public static int getRecursion(int num){
if(num==1){
return 1;
}
else{
return num*getRecursion((num-1));
}
}
}