The following is based on a modification of moshe's code posted here. If the following is the desired answer, it seems to have little to do with programming. Rather, it is a math problem. Is there any better/other solution?

```
public boolean isPowerOfThree(int n) {
if(n<1) return false;
int x = (int)(Math.round(Math.log(n) / Math.log(3)));
if (Math.pow(3,x)<=Integer.MAX_VALUE && ((int)Math.pow(3,x)) == n) {
return true;
}
else
return false;
}
```

**Update**

Or this one line solution: https://leetcode.com/discuss/78481/java-one-line-solution-using-math-knowledge