• 剑指offer_面试题11 数值的整数次方_考察代码的完整性


    测试通过代码:

    package t0825;
    
    public class Power {
         public static void main(String[] args){
            System.out.println(Power(2.5,3));
            System.out.println(Power(0.00000001,3));
            System.out.println(Power(0.00000001,-3));
            System.out.println(Power(2,-3));
            System.out.println(Power(10,10));         
         }
         /*
          * 大数问题
          */
         public static double Power(double base, int exponent) {
             double result=1.0;
             if(equal(base,0.0) && exponent<0){ //当基于为零时,多少次方都为零
                return 0.0; 
             }    
             int absExponent=0;
             if(exponent<0)
                 absExponent=-exponent;   //如果为负数,取反求倒数;
             else
                 absExponent=exponent;
             result = PowerAlthmn(base,absExponent);
             if(exponent<0)
                 result = 1.0/result;         
             return result;
         }
         public static boolean equal(double num1,double num2){
            if((num1-num2)>-0.0000001 && (num1-num2<0.0000001))
                return true;
            else
                return false;
         }
         public static double PowerAlthmn(double base,int exponent){
             double result1=1.0;
             while(exponent!=0){
                 result1=result1*base;
                 exponent--;
             }         
             return result1;
         }
    }
  • 相关阅读:
    爬弹幕
    写了这么多行就给我30,呜呜呜
    ticket
    yield求平均数
    协程原理
    爬取一类字二类字的信息和笔顺gif图片
    关于CRF的相关阅读
    embedding size与vocabulary size之间的关系: e = v**0.25
    pandas多个值取数
    转 pandas pivot
  • 原文地址:https://www.cnblogs.com/snowwhite/p/4758649.html
Copyright © 2020-2023  润新知