The following algorithm concerns what happens when we take any positive integer n: If n is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The following algorithm concerns what happens when we take any positive integer n: If n is even, then n is updated to n/2; if n is odd, then n is updated to 3*n+1. The algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1. Write a java program that takes a single value as input and show how the algorithm works. You need to print all of numbers in this sequence starting from your input value n until 1. The following algorithm concerns what happens when we take any positive integer n: If n is even, then n is updated to n/2; if n is odd, then n is updated to 3*n+1. The algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1. Write a java program that takes a single value as input and show how the algorithm works. You need to print all of numbers in this sequence starting from your input value n until 1.
Expert Answer:
Answer rating: 100% (QA)
import javautilScanner public class Collatz public st... View the full answer
Related Book For
Posted Date:
Students also viewed these computer network questions
-
The Smelting Department of Kiner Company has the following production data for November 4 Production: Beginning work in process 2.700 units that are 100% complete as to materials and 22% complete as...
-
Hailstone sequence (due 28 feb 2015) take any natural number n. if n is even, divide it by 2 to get n // 2. if n is odd, multiply by 3 and add 1 to obtain 3 * n + 1. repeat the process indefinitely....
-
The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm: n= n/2, if n is even 3
-
Scenic Ventures is considering an investment in a start-up firm offering ecotourism excursions in Costa Rica. Scenic Ventures estimates that, if the venture is successful, the ecotourism company will...
-
In a study on attention and performance of memory tasks, six participants attended a 1-hour lecture on a topic chosen at random. Following this lecture, they received a survey testing their knowledge...
-
Consider the steady-state diffusion of hydrogen through the walls of a cylindrical nickel tube as described in Problem 6.D3. One design calls for a diffusion flux of 2.5 10-8mol/m2.s, a tube radius...
-
Information systems auditors should be most concerned about management's decision to undertake outsourcing of the information systems function when: a. A long-term contract with the outsourcing...
-
The manager of the greeting card section of Harveys department store is considering her order for a particular line of holiday cards. The cost of each box of cards is $3; each box will be sold for $5...
-
One of the principal tasks of management is identifying and selecting appropriate goals and courses of action. This is referred to as Question 1 6 options: planning organizing leading controlling
-
Explain how personal selling can help solve the problem of information overload.
-
A. Fella Impian Berhad is a manufacturing company, the company is organized into five cost centres. Shown below are next year's budgeted operating costs for the company: Direct allocated costs:...
-
For each of the following threats, give a control that might reduce exposures: a. Pirated software b. Violation of the licensing conditions pertaining to a proprietary database c. Employee use of an...
-
Briefly distinguish between viruses and worms. List two controls over viruses and worms (one for viruses and one for worms) that security administrators might implement to reduce exposures.
-
Give one preventive control and one detective control over the activities of computer hackers.
-
What are the controls of last resort? Briefly explain the nature of each.
-
Briefly describe the major components of an emergency plan.
-
discuss the ethical considerations surrounding viral research, including issues related to dual-use research of concern (DURC), biosafety and biosecurity protocols, and the responsible conduct of...
-
Let (X. A. p) be a measure space. Show that for any A,B A, we have the equality: (AUB)+(An B) = (A) + (B).
-
Write the element of H in the form a 1 + a 2 i + a 3 j + a 4 k for a i R. (i + j) -1
-
Let F E F where F is an algebraic closure of a field F. The field E is a splitting field over F if and only if E contains all the zeros in F of every polynomial in F[x] that has a zero in E.
-
Find the degree and a basis for the given field extension. Be prepared to justify your answers. Q( 3 2, 3 6, 3 24) over Q
-
Skyway Inc. identified a cost pool related to material handling costs for its manufacturing process. Using historical data and ordinary least squares regression, Skyway summarized two different...
-
Assume that a manufacturing company is determining the optimal minimum level of cash to maintain in a financial institution to cover short-term needs. Separately consider each of the following...
-
Prior to the Tax Cuts and Jobs Act of 2018 (TCJA), multinational firms domiciled in the United States did not have to pay U.S. income taxes on foreign earnings, unless those earnings were returned...
Study smarter with the SolutionInn App