Weekend Task - Happy Number #25
Replies: 35 comments
|
import java.util.Scanner; public class Happynumber { } |
|
|
import java.util.Scanner; public class HappyNumbers { |
|
`import java.util.Scanner; }` |
|
|
|
import java.util.Scanner; public class HappyNumber { }`` |
|
`import java.util.Scanner; class Happy { } public class HappyNum { |
|
`import java.util.; } |
|
HAPPY-UNHAPPY NUMBER } |
|
** Happy Number** `import java.util.Scanner; public static void main(String[] args) { } |
|
|
|
|
|
|
`import java.util.Scanner; public class HappyNumber { } |
|
|
`import java.util.Scanner; public class HappyNum { } |
|
`import java.util.*; public class HappyNumber { }` |
|
import java.util.ArrayList; /* For example, 32 is a happy number as the process yields 1 as follows: 3^2 + 2^2 = 13 Check whether a number is a happy number, take 'k' as input, and print the first 'k' happy numbers from this number. public class HappyNumber { } |
|
|
import java.util.*; public static void main(String[] args) } |
|
`import java.util.Scanner; public class HappyNumber { } ` |
|
import java.util.Scanner; public class Happy { public static void main(String[] args) { |
|
|
|
`import java.util.Scanner; public class HappyNumber { public static void main(String[] args) { } |
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
A happy number can be defined as a number that will yield 1 when it is replaced by the sum of the square of its digits repeatedly. If this process results in an endless cycle of numbers containing 4, then the number is called an unhappy number.
For example, 32 is a happy number as the process yields 1 as follows:
Some of the other examples of happy numbers are 7, 28, 100, 320, and so on. The unhappy number will result in a cycle of 4, 16, 37, 58, 89, 145, 42, 20, 4. If a number is happy, then all members of its sequence are happy; if a number is unhappy, all members of the sequence are unhappy.
Check whether a number is a happy number, take 'k' as input, and print the first 'k' happy numbers from this number.
All reactions