```
public boolean isHappy(int n) {
for (int sum = 0; n / 10 != 0 || n % 2 != 0 || (n == 1); n = sum, sum = 0) {
for (int i = n; i > 0; i /= 10)
sum += Math.pow(i % 10, 2);
if (sum == 1)
return true;
}
return false;
}
```