IntegerPowersofNumericalValues题目描述给出一个double类型的浮点数基数和一个int类型的整数指数。求基数的指数幂。确保基数和指数不同时为0。TopicLink:IntegerPowerofNumericalCode/***Title:IntegerPowerofNumerical*题目描述*给定一个double类型的浮点数基数和一个int类型的整数指数。求基数的指数幂。*保证底数和指数不等于0*话题链接:*https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00?tpId=13&&tqId=11165&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-采访/问题排名*/publicclassJz12{publicdoublePower(doublebase,intexponent){doubleresult=0;如果(指数>0){结果=基数;while(exponent>1){结果*=base;指数--;}}else{结果=1;while(exponent<=-1){结果/=base;指数++;}}返回结果;}publicstaticvoidmain(String[]args){Jz12jz12=newJz12();System.out.println(jz12.Power(2,3));System.out.println(jz12.Power(2,-3));}}【每日留言】时光不会倒流,把握每一天属于自己的早晨。
