```
public boolean isHappy(int n) {
HashSet<Integer> hash = new HashSet<Integer>();
if(n <= 0) return false;
while(n < Integer.MAX_VALUE){
int i = 0;
int j = 10;
if(n == 1) return true;
if(hash.contains(n)) return false;
else hash.add(n);
while(n != 0){
i += (n % j) * (n % j);
n = (n - n % j) / 10;
}
n = i;
}
return false;
}
```