```
public class Solution {
public boolean isHappy(int n) {
n = square(n);
while (n>9){
n = square(n);
}
if (n==1){return true;}
return false;
}
public int square(int n){
int sum=0;
while(n>0){
sum = sum+(n%10)*(n%10);
n = n/10;
}
return sum;
}
}
```