Why would this not work?


#1

public int isPower(int A) {
if(A == 1) return 1;
for(int i=2; i<=A/2; i++){
double av = Math.pow(A, 1/i);
if((av - (int)av) == 0)
return 1;
}
return 0;
}


#2

(av - (int)av) == 0)

av - (int)av) wont be necessarily giving 0 it will be something like 0.0000001.
Put print statements and see.