```
public boolean isHappy(int n) {
HashSet<Integer> hashSet = new HashSet<Integer>();
while (!hashSet.contains(n)) {
hashSet.add(n);
int temp = 0;
while (n > 0) {
temp += Math.pow(n % 10, 2);
n /= 10;
}
n = temp;
}
return n == 1;
}
```