题解 | #数值的整数次方#

数值的整数次方

https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00

import java.util.*;
public class Solution {
    public double Power(double base, int exponent) {
        //当次方根为负数时
        if(exponent < 0){
            base = 1 / base;
            exponent = -exponent;
        }
        double res = 1.0;
        //对次方进行累乘
        for(int i = 0; i < exponent; i++){
            res *= base;
        }
        return res;
  }
}

全部评论

相关推荐

2025-12-22 15:04
江西农业大学 Web前端
SaviorSu:直接说下学期可以请假,一般情况学校允许我26届,大三就直接去实习了
点赞 评论 收藏
分享
抓蛙得要春天:别想那么多,找得到再说,有面试再说
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务