public class DiGui
{
public static void main(String[] args){
System.out.println("请输入一个整数:");
Scanner s = new Scanner(System.in);
int n = s.nextInt();
System.out.println(method(n));
}
public static long method(int n)
{
long value = 0;
if(n == 1)
{
value = 1;
}
else
{
value = n * method(n-1);
}
return value;
}
}
java语言实现:利用递归方法求n!
最新推荐文章于 2024-06-07 00:36:28 发布