Happy Number Program I wrote this program, to determine if any given number is happy, and would like to know of any improvements that can be made to make it better. I have tested it, but whether or not it works perfectly I have no idea, there might be some numbers that get through, although I doubt it.

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class HappyNumber
{
    public static void main(String[] args)
    {
        System.out.print("Please enter a number: ");
        int number = new Scanner(System.in).nextInt(), value;

        Set&lt;Integer&gt; unique = new HashSet&lt;Integer&gt;();

        while (unique.add(number))
        {
            value = 0;
            for (char c : String.valueOf(number).toCharArray())
                value += Math.pow(Integer.parseInt(String.valueOf(c)), 2);
            number = value;
        }

        System.out.println(number == 1 ? "Happy" : "Not Happy");
    }
}
Apart from what @RubberDuck said, you can also do a bit less work by not
converting from/to String, but iterating over the digits one by one
directly.  I've also moved the value to where it is initialised, that
way its scope is better visible.

After making those changes I arrive at the following snippet.  isHappy
or (isHappyNumber) can be reused and the main function only does
interface stuff.

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class HappyNumber
{
    public static boolean isHappy(int number)
    {
        Set&lt;Integer&gt; unique = new HashSet&lt;Integer&gt;();

        while (unique.add(number))
        {
            int value = 0;
            while (number &gt; 0)
            {
                value += Math.pow(number % 10, 2);
                number /= 10;
            }
            number = value;
        }

        return number == 1;
    }

    public static void main(String[] args)
    {
        System.out.print("Please enter a number: ");
        int number = new Scanner(System.in).nextInt();
        System.out.println(isHappy(number) ? "Happy" : "Not Happy");
    }
}