```
public class Solution {
public boolean isHappy(int n) {
if(n==1) return true;
int[] array = new int[810];
if(n<810) array[n]++;
int sum;
while(n!=1){
sum=0;
while(n>0){
sum+=(n%10)*(n%10);
n=n/10;
}
array[sum]++;
if(array[sum]>1) return false;
n=sum;
}
return true;
}
```

}