private static int isHappy(String str)
	{
		int num;
		ArrayList<Integer> numbersSeen;
		num = Integer.parseInt(str);
		numbersSeen = new ArrayList<Integer>();
		while(num != 1)
		{
			int q;
			int r;
			q = num;
			r = 0;
			while(q > 0) //Loop through each digit.
			{
				r += q%10 * (q%10); //Add the squares of each digit
				q /= 10;
			}
			if(numbersSeen.contains(r)) //We have then found a loop.
			{
				return 0;
			}
			numbersSeen.add(r);
			num = r;
		}
		return num;
	}