【发布时间】:2018-07-18 10:47:20
【问题描述】:
class PowerRec
{
static double powRec(double x, int power)
{
if (power == 1){
return x;
}
return x * powRec(x, power - 1);
}
public static void main(String args[])
{
double x = 2;
System.out.println (x + " to the fourth is " + powRec (x, 4));
}
}
【问题讨论】:
-
它没有。不过
x * (x ^ (n - 1)) == x ^ n -
做一些代码布局揭示了一条令人毛骨悚然的路线。修好了。
标签: java recursion exponentiation