Question: Java Programming The Collatz Conjecture is a conjecture that states that for any positive integer, if you repeat the following over and over again: if

Java Programming

The Collatz Conjecture is a conjecture that states that for any positive integer, if you repeat the following over and over again:

if the n is even, divide it in half

else, multiply it by 3 and then add 1. Then eventually, you will arrive at the number 1.

This method should return the number of steps that it takes to get from the specified number to 1.

For example, if startingNumber were 7, then the Collatz conjecture process would be:

7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.

The number of steps in the sequence was 17, so getNumColltzSteps(7) should return 17.

@param startingNumber the number at the first step in the Collatz conjecture process

@return the number of operations in the Collatz conjecture that were needed to get to 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 Databases Questions!