How to write a program in java for a happy number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to write a program in java for a happy number

happy number is a number whose ultimate sum is 1. eg.lets take the number 82. sum of its digits is 10. and sum of digits of 10 is 1. so 82 is a happy number.

21st Feb 2017, 6:41 AM
Pratham
Pratham - avatar
3 Answers
+ 4
try to write a block of code which calculates the sum of the digits, then for example execute this code in a while (sum < 10) , now it will calculate the sum, till the sum is smaller than 10, almost finished just pus a simple if statement and check if the sum is 1 that's it note, I am not writing any code, because I won't you to learn something, and not just get the answer hope this helps ^^
21st Feb 2017, 6:51 AM
Kamil
Kamil - avatar
3rd Apr 2019, 10:31 PM
Prantik Sarkar
Prantik Sarkar - avatar
+ 1
I have written
6th May 2017, 4:45 AM
Pratham
Pratham - avatar