日期:2014-05-20 浏览次数:20866 次
static double power(double x, int n){
if(n>1){
System.out.println(" n is :"+n+"。call method power("+x+","+(n-1)+")。"+" return is "+x+"*power("+x+","+(n-1)+")。");
return x*power(x,n-1);
}
else if(n <0)
return 1.0/power(x,-n);
else {
System.out.println(" the method end here。last method is power("+x+","+n+") ,return is :"+(n==0 ? 1.0:x));
return n==0 ? 1.0:x;
}
}
------解决方案--------------------
你用dubug以下一步一步看看 就很好了
------解决方案--------------------
java程序员群 4247660 欢迎大家的加入
------解决方案--------------------
你把我加的注释执行下,应该能明白吧。。。