public boolean isHappy(int n) {

		HashSet<Integer> set = new HashSet<Integer>();
		int i = n;
		while (!set.contains(i)) {
			set.add(i);
			int tmp = 0, m;
			while (i > 0) {
				m = i % 10;
				tmp += m * m;
				i = i / 10;
			}
			if (tmp == 1)
				return true;

			i = tmp;
		}

		return false;

	}