剑指offer(12)数值的整数次方
public class Solution {
public double Power(double base, int exponent) {
double result = 1.0;
if(exponent == 0){
return 1;
}else if(exponent < 0){
exponent = -exponent;
if(base == 0){
throw new RuntimeException("该操作不合法");
}else{
while(exponent > 0){
result *= base;
exponent --;
}
return 1/result;
}
}else{
while(exponent > 0){
result *= base;
exponent--;
}
return result;
}
}
}