Where is the mistake?
package com.codegym.task.task39.task3910;
/*
isPowerOfThree
*/
public class Solution {
public static void main(String[] args) {
System.out.println(isPowerOfThree(-27)); // true
System.out.println(isPowerOfThree(-81)); // false
System.out.println(isPowerOfThree(81)); // true
System.out.println(isPowerOfThree(729)); // true
System.out.println(isPowerOfThree(567)); // false
}
public static boolean isPowerOfThree(int n) {
if (n > -3 && n < 3) return false;
int counter = 0, tmp = n;
while (true) {
if (n % 3 == 0) {
n /= 3;
counter++;
} else
return false;
if (Math.abs(n) == 1) {
if (tmp > 0) {
return true;
} else {
if (counter % 2 == 0)
return false;
else
return true;
}
}
}
}
}