/* 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? } }