public boolean isHappy(int n) {
if( n == 0 ){
return false;
}
while( n != 1 && n != 4 ){
n = sumOfSquares(n);
}
return (n == 1);
}
public int sumOfSquares(int n){
int val = 0;
while( n > 0 ){
int tempMul = n % 10;
val += (tempMul * tempMul);
n = n / 10;
}
return val;
}
2ms Java. Based on "Circle of 4 is unhappy." [From Wiki]


@marcleclair read this http://io9.gizmodo.com/5934819/whyfouristhenemesisofhappynumbers. If you ever get a four in the process, it will repeat, and repeat forever. So, we stop if we get a four. I hope it is clear.