public class Solution {

```
public boolean isHappy(int n) {
while (true) {
n = cal(n);
if (n == 1) {
return true;
} else if (n == 4) {
return false;
}
}
}
private int cal(int n) {
int sum = 0;
while (n != 0) {
int tmp = n % 10;
sum = sum + tmp * tmp;
n = n / 10;
}
return sum;
}
```

}