In order to find a rule to break out the loop, I start calculating 2 and find a loop at 4, then 3,5,6,9 will all go into that loop. So in 1-9, only 1 and 7 are happy numbers. Also I find all numbers' calculation will goes into a single digit at some time. So what I did is just calculate happy sum and when it is a single digit, check if it is 1 or 7 ^.^

```
public boolean isHappy(int n) {
if(n<=0) return false;
while(true){
int sum=0;
while(n!=0){
sum+=(n%10)*(n%10);
n=n/10;
}
if(sum/10==0){
if(sum==1||sum==7) return true;
else return false;
}
n=sum;
}
}
```