Question: Goal: Learn to write do - while loops. Assignment: Given the following sequence of operations: starting from a number U 0 , divide it by

Goal: Learn to write do-while loops.
Assignment: Given the following sequence of operations: starting from a number U0, divide it by 2 if it is even, or multiply it by 3 and add 1 if it is odd. Collatz's conjecture states that this sequence will always converge to 1, no matter the starting number.
Assume a Scanner stdin has already been declared and instantiated. int variable un will be input by the user and serve as a starting point, and int variable counter will serve to track the progress in the sequence. Write a do-while loop that implements this sequence of operations until Un reaches 1. Print out the values of Un during the whole process.
Sample output (user input enclosed in <>):
<7>
u0=7
u1=22
u2=11
u3=34
u4=17
u5=52
u6=26
u7=13
u8=40
u9=20
u10=10
u11=5
u12=16
u13=8
u14=4
u15=2
u16=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!