```
public static boolean isHappy(int n) {
int num = n;
int[] tag = new int[244];
while(num != 1){
int temp = num;
num = 0;
while(temp >= 10){
num += Math.pow(temp % 10,2);
temp /= 10;
}
num += Math.pow(temp,2);
if(tag[num] == 1)
break;
tag[num] = 1;
}
return num == 1;
}
```