Computer Science, asked by jhalakshah0106, 5 months ago

A happy number is defined as:
Take a positive number and replace the number by the sum of the squares of its digit, Repeat the process until the number equals 1(one).
If the number ends with 1 then it is called a happy number.
Write a program to input a number and check whether it a ‘happy number’ or not the program
Display a message accordingly.
Sample input: 31
solution=31=9+1=10=1+0=1
Sample output: a happy number
PLEASE HELP ME!!!

Answers

Answered by maneetjassal
2

Answer:

..........

Explanation:

Plz Mark me as Brainliests......

Answered by annanya2417
0

Answer:

Explanation:

import java.util.Scanner;

public class HappyNumber

{

   public static void main(String args[]) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter number to check: ");

       long num = in.nextLong();

       long sum = 0;

       long n = num;

       do {

           sum = 0;

           while (n != 0) {

               int d = (int)(n % 10);

               sum += d * d;

               n /= 10;

           }

           n = sum;

       } while (sum > 6);

       if (sum == 1) {

           System.out.println(num + " is a Happy Number");

       }

       else {

           System.out.println(num + " is not a Happy Number");

       }

   }

}

Similar questions