public class Solution {

```
public boolean isHappy(int n) {
Set<Integer> visited = new HashSet<Integer>();
if(n == 1) {
return true;
}
while(visited.add(n)) {
int m = 0;
while(n > 0) {
m += Math.pow(n%10, 2);
n /= 10;
}
n = m;
if(n == 1) {
return true;
}
}
return false;
}
```

}