标签:base div nbsp ase ble bsp style ret logs
直接上代码了,不解释,很简单的,主要考虑边界值问题
public class Solution { public double Power(double base, int exponent) { boolean isFlag = false; if(exponent == 0) return 1; if(exponent == 1) return base; if(exponent<0) { exponent = -exponent; isFlag = true; } double total =1 ; int i = 1; for( ; i <= exponent ; i++){ total = total * base; } if(isFlag){ return 1.0/total; } else { return total; } } }
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
标签:base div nbsp ase ble bsp style ret logs
原文地址:http://www.cnblogs.com/CloudStrife/p/7224585.html