zoukankan      html  css  js  c++  java
  • 326.Power of Three

    /*
    
    Given an integer, write a function to determine if it is a power of three.
    
    Follow up:
    Could you do it without using any loop / recursion?*/
    public class PowerOfThree {
        private  static final double EX=10e-15;
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
        int d=243;
            System.out.println(isPowerOfThree(d));
        }
        
         public static boolean isPowerOfThree(int n) {
                if(n==0)
                    return false;
                double res=Math.log(n)/Math.log(3);
                System.out.println(res);
                return (Math.abs((res-Math.round(res)))<EX);  //注意为什么不能用floor和ceil   注意double   其实还可以bigdecimal?
            }
        }
  • 相关阅读:
    ruby 类库组成
    ruby 数据类型Number
    ruby require的使用
    ruby $LOAD_PATH及类加载
    ruby编码说明
    RubyMine常用快捷键
    基础
    基础
    基础
    基础
  • 原文地址:https://www.cnblogs.com/kydnn/p/5148195.html
Copyright © 2011-2022 走看看