```
public boolean isHappy(int n) {
int num = n;
int count = 0;
while (num != 1)
{
count++;
if (count > 100) return false;
int sum = 0;
while (num != 0)
{
int a = num%10;
sum += Math.pow(a, 2);
num /= 10;
}
num = sum;
}
return true;
}
}
```