```
public boolean isHappy(int n) {
while(n!=1&&n!=4){
int res = 0;
while(n>0){
int r = n%10;
res+=r*r;
n=n/10;
}
n=res;
}
if(n==1) return true;
else return false;
}
```