public int f(int n) throws Exception { if(n<0) throw new Exception("参数n不能小于零"); if(n==0) return n+1 ; return n*f(n/2) ;} Java写了个方法,你看行不?