public class Solution {
public static double Power(double base, int exponent) {
if (exponent == 0)
return 1;
else if (exponent % 2 == 1 ) // 对于n为正数的情况
return Power(base, exponent - 1) * base;
else if (exponent % 2 == -1 ) // 对于n为负数的情况
return Power(base, exponent + 1) / base;
else
{
double temp = Power(base, exponent / 2); // 对于n为负数的情况
return temp * temp;
}
}
public static void main(String[] args) {
System.out.println(-1%2);
System.out.println(Power(2.1000,-2));
}
}