Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program needs to be in Java. 4. The 3N+1 Problem Given a positive integer N, define number, then divide N by 2; but if

image text in transcribedimage text in transcribed

This program needs to be in Java.

4. The 3N+1 Problem Given a positive integer N, define number, then divide N by 2; but if N is odd, then multiply N by 3 and add 1. Continue to generate numbers in this way until N become equal to 1. For example, starting from N 3, which is odd, we multiply N by 3 and add 1, giving N 10. Then, since N is even, we divide by 2, giving N-5. We continue in this way, stopping when we reach 1. The complete sequence is: 3, 10, 5, 16, 8, 4, 2,1 Write a program that will read a positive integer from the user and will print out the 3N+1 sequence starting from that integer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

What is meant by the term industrial relations?

Answered: 1 week ago