题目描述
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方
public class Solution {
public double Power(double base, int exponent) {
if(exponent > 0){
double temp = 1;
for(int i = 0; i < exponent; i++){
temp = temp * base;
}
return temp;
}else if(exponent < 0){
double temp = 1;
exponent = -exponent;
for(int i = 0; i < exponent; i++){
temp = temp * base;
}
temp = 1 / temp;
return temp;
}
return 1;
}
}