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
-
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...
-
Compare and discuss the formulas for resistance and for capacitor when connected in series and in parallel.
-
The article Nine Out of Ten Drivers Admit in Survey to Having Done Something Dangerous (Knight Ridder Newspapers, July 8, 2005) reported the results of a survey of 1100 drivers. Of those surveyed,...
-
As a gambling facility, MGM Desert Inn, Inc., regularly holds and executes negotiable instruments. During a period of two months, patron William E. Shack Jr. entered MGM and delivered eight checks to...
-
The comparative condensed income statements of Hendi Corporation are shown below. Instructions(a) Prepare a horizontal analysis of the income statement data for Hendi Corporation using 2010 as a...
-
An US firm agrees to sells a Yen Bond at 4% to a Japanese firm and purchases an USD bond at 8% from the Japanese firm. Yen interest rate: 1% (continuous compounded) USD interest rate: 2% (continuous...
-
Barone, Inc. is involved with several situations that possibly involve contingencies. Each is described below. Barone's fiscal year ends December 31, and the 2021 financial statements are issued on...
-
Must any differentiable function f [a, b] R have a maximum and minimum value? Why? If f: [a, b] R is differentiable and f(a) = f(b), must f have a maximum and minimum value in (a, b)?
-
Find lim x 2 36x + 21 x + 2 Choose 1 answer:
-
What is the pH of a buffer solution containing 0.40M NH 4 Cl and 0.17M of NH 3 if the pKa of NH 4 + is 9.25. Can use the 5% approx rule.
-
Companies can benefit significantly from combining the conventional strategies of overall cost leadership and differentiation. This strategy, referred to as a hybrid one, enables a business to...
-
CNBC's short documentary entitled "How Netflix Lost Its Edge To Disney+" chronicles Netflix's launch, boom, and commencement of its decent from market share. a. With streaming services becoming a war...
-
When you made the benchmarking activity and reviewed your own building, did you realize anything about your building that you never thought of before? Ask yourself the same question about the...
-
Prepare the financial statements for following Baker's Bikes. Baker's Bikes is a local bike repair, sales and service shop specializing in road bikes. Baker's Bikes carns revenue through a.) service...
-
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
-
Match the following terms in the first column with the definitions or examples in the second column. L DBMS 2. Transaction file 3. Data warehouse 4. Primary key 5. SQL 6. CASE tool 7. Hungarian...
-
Currently, rotational database technology is probably the most prevalent database technology used in modern information technology shops. But database technology is an evolving field and new...
-
Create the Web site using appropriate technologies, getting a domain name, and so forth. Set up e-mail with the domain name, as well. If it is appropriate for the company to have shopping cart and...
Study smarter with the SolutionInn App