The idea is that the ternary number that is power of 3 will be something like 10,100,1000, etc, analogous to binary numbers that are powers of 2.

```
public boolean isPowerOfThree(int n) {
String s = Integer.toString(n, 3);
if (s.contains("2")) return false;
int result = Integer.valueOf(s, 2)&(Integer.valueOf(s, 2)-1);
return result==0&n>0?true:false;
}
```