Question: 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
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.
Step by Step Solution
3.52 Rating (166 Votes )
There are 3 Steps involved in it
import javautilScanner public class Collatz public st... View full answer
Get step-by-step solutions from verified subject matter experts
