```
public class Solution {
public boolean isHappy(int n) {
boolean[] array = new boolean[162];
int testnumber=0;
do{
testnumber=CalculateSquareSum(n);
if(testnumber==1)return true;
if(testnumber<162 && array[testnumber]==true) return false;
n=testnumber;
if(testnumber<162) array[testnumber]=true;
}while(true);
}
public static int CalculateSquareSum(int n){
int result=0;
do{
result+=(int)Math.pow(n%10, 2);
}while((n/=10)!=0);
return result;
}
}
```