subject

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 either 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, while those that do not end in 1 are unhappy numbers. For example, 13 is a happy number since 1^2 + 3^2 = 1 + 9 = 10, 1^2 + 0^2= 1 + 0 = 1. And 85 is an unhappy number since 8^2 + 5^2 = 64 + 25 = 89, 8^2 + 9^2 = 64 + 81 = 145, 1^2 + 4^2 + 5^2= 1 + 16 + 25 = 42, 4^2 + 2^2 = 16 + 4 = 20, 2^2 + 0^2 = 4, 4^2= 16, 1^2 + 6^2 = 1 + 36 = 37, 3^2 + 7^2 = 9 + 49 = 58, 5^2 + 8^2 = 25 + 64 = 89, which is a repeated result. Write your own Java program to check whether a positive integer represented by a string is an happy number. For example, a typical string input looks like "2345678901234567899999". Note the number represented by this string could be larger than any long integers. Therefore, you should not use any method like parselnt(). You need to write your own code to hand this string. Using the code that can check whether a number represented by a string is an happy number to find all the happy numbers between 1 and 10,000, print out all the happy numbers between 9,001 and 10,000, Also in your report, you need to draw UML diagrams for your classes. find a very large happy number and a very large unhappy number. These numbers need to have at least 20 digits. Moreover, print out the sequences like the ones in examples above for 13 and 85, to show that the sequence eventually goes to 1 or the sequence is repeating.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 15:00
Barbara is interested in pursuing a career in the science and math pathway. which qualifications will her reach that goal? a.an advanced knowledge of physics and math b.an advanced knowledge of engineering and math c. an advanced knowledge of physics and robotics an d. advanced knowledge of machinery and math
Answers: 1
question
Computers and Technology, 24.06.2019 18:30
What is the local portion of the e-mail address below? [email protected] a.) @ b.) biz c.) gumchewer d.) twrigley
Answers: 1
question
Computers and Technology, 25.06.2019 05:10
Assume that two parallel arrays have been declared and initialized: healthoption an array of type char that contains letter codes for different healthcare options and annual cost an array of type int. the i-th element of annual cost indicates the annual cost of the i-th element of healthoption. in addition, there is an char variable, best2.write the code necessary to assign to best2 the health option with the lower annual cost, considering only the first two healthcare options. thus, if the values of healthoption are 'b', 'q', 'w', 'z' and the values of annualcost are 8430, 9400, 7050, 6400 your code would assign 'b' to best2 because 8430 is less than 9400 and is associated with 'b' in the parallel array. (we ignore 'w' and 'z' because we are considering only the first two options.)
Answers: 1
question
Computers and Technology, 25.06.2019 16:00
What are the two parts of an event? a. the object and the property b. the icon and the tooltip c. the frame and the coordinate d. the condition and the action
Answers: 1
You know the right answer?
A happy number is a number defined by the following process: Starting with any positive integer, rep...
Questions
question
Mathematics, 23.09.2019 13:50
question
Mathematics, 23.09.2019 13:50