```
class Solution {
public boolean isHappy(int n) {
boolean[] hasAppeared = new boolean [811];
for(boolean temp: hasAppeared){
temp = false;
}
while(n != 1){
int temp = 0;
while(n != 0){
temp += (n % 10) * (n % 10);
n /= 10;
}
n = temp;
if(hasAppeared[n])return false;
hasAppeared[n] = true;
}
return true;
}
}
```