*hi there here is my answer for this challenge :
Write an algorithm to determine if a number n is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
my code works and outputs a true value only if the number is a happy one*
public class Main {
public static void main(String[] args) {
System.out.println(isHappy(12));
}
public static boolean isHappy(int number) {
while (number != 1 ) {
number = SumOfintegers(number); //to keep looping until It find sum=1
}
return true ;
}
public static int SumOfintegers(int number){
int sum =0;
int news = 0;
while (number > 0) {
int num = number % 10;
number /= 10;
news = num * num;
sum = sum + news;
}
return sum;
}
}