System.out.println("输入n,按回车:")
Scanner s = new Scanner(System.in)
Integer n = Integer.parseInt(s.next())
Integer re = factorial(1, n)
System.out.println(re)
}
public static Integer factorial(Integer a, Integer b){
if(b == 1){
return a * b
}else{
return a * b * factorial(a, b-1)
}
}
public class bb{
public static void main(String args[])
{
System.out.println(getpower(2,10))
}
public static int getpower(int x,int y)//此为您要的递归方法
{
if(y==0)
return 1
else if(y==1)
return x
else return x*getpower(x,y-1)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)