public static int func(int n){
int sum = 0;
while(n>0){
int dig = n%10;
sum+=dig*dig;
n/=10;
}
return sum;
}
public boolean isHappy(int n) {
int slow = n;
int fast = func(n);
while(slow!=fast){
slow = func(slow);
fast = func(func(fast));
}
return slow ==1;