Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a java program that will read a positive integer from the user and will print out the 3 N + 1 sequence starting from
Write a java program that will read a positive integer from the user and will print out the sequence
starting from that integer. The program should also count and print out the number of terms in the
sequence.
Given a positive integer, define the sequence starting from as follows: If is an even
number, then divide by two; but if is odd, then multiply by and add Continue to generate
numbers in this way until becomes equal to
You must validate the starting number must be positive.
C:WINDOWS systemcmdexe
There were terms in the sequence.Press any key to continue
Hint:
For example, starting from which is odd, we multiply by and add giving Then,
since is even, we divide by giving We continue in this way, stopping when we reach
giving the complete sequence:
Ask user to input a positive number;
Let be the user's response;
while is not positive:
Print an error message;
Read another value for ;
Let counter ;
while is not :
if is even:
Compute ;
else
Compute ;
output ;
Add to counter;
output the counter;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started