We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ee9a95 commit f1aafadCopy full SHA for f1aafad
EASY/src/easy/HappyNumber.java
@@ -0,0 +1,29 @@
1
+package easy;
2
+
3
+import java.util.HashSet;
4
+import java.util.Set;
5
6
+public class HappyNumber {
7
8
+ public static boolean isHappy(int n) {
9
+ if(n == 1) return true;
10
+ Set<Integer> set = new HashSet();
11
+ while(n != 1){
12
+ String str = String.valueOf(n);
13
+ n = 0;
14
+ for(int i = 0; i < str.length(); i++){
15
+ int temp = Character.getNumericValue(str.charAt(i));
16
+ n += temp*temp;
17
+ }
18
19
+ if(!set.add(n)) return false;
20
21
+ return false;
22
23
24
25
+ public static void main(String...strings){
26
+ int n = 7;
27
+ System.out.println(isHappy(n));
28
29
+}
0 commit comments