public class Demo20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个正整数");
int n = sc.nextInt();
if(n==1){
System.out.println(n+"是快乐数");
}
Set<Integer> seen = new HashSet<>();
while (!seen.contains(n)) {
seen.add(n);
n =getNext(n);
if(n==1){
System.out.println(n+"是快乐数");
return;
}
}
System.out.println(n+"不是快乐数");
}
public static int getNext(int n) {
int totalSum = 0;
while (n > 0) {
totalSum += Math.pow(n % 10, 2);
n /= 10;
}
return totalSum;
}
}