```
public boolean isUgly(int num) {
if (num >=1 && num <5)
return true;
if (num < 1 || num == Integer.MAX_VALUE)
return false;
float n = (float) num;
while (n % 2 == 0) {
n /= 2;
}
if (n == 1)
return true;
while (n % 3 == 0) {
n /= 3;
}
if (n == 1)
return true;
while (n % 5 == 0) {
n /= 5;
}
if (n == 1)
return true;
return false;
}
```