```
class Solution {
public boolean isHappy(int n) {
if(n<=0) return false;
int count=0;
int x;
while(count<30) //急中生智，防止无限循环
{
x=ret(n);
if(x==1) return true;
count++;
n=x;
}
return false;
}
public int ret(int n)
{
int ret=0;
while(n>0)
{
ret+=(n%10)*(n%10);
n/=10;
}
return ret;
}
}
```