```
public boolean isHappy(int n) {
if(n==0) return false;
int temp=0;
while(n!=0){
temp+=(n%10)*(n%10);
n=n/10;
}
if(temp==1||temp==4||temp==16||temp==37||temp==58||temp==89||temp==145||temp==42||temp==20) return temp==1;
return isHappy(temp);
}
```