A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process un
You would have to keep a record of all the numbers you have produced so far in the sequence, and if one of them comes up a second time you know you have a loop which will never reach 1. A set is probably a good choice for a place to store the numbers.