Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Start with any positive number n. If n is even divide it by 2, if n is odd multiply by 3 and add 1.

1. Start with any positive number n. If n is even divide it by 2, if n is odd multiply by 3 and add 1. Repeat until n becomes 1. The sequence that is generated is called a bumpy sequence. For example, the bumpy sequence that starts at n = 10 is: 10, 5, 16, 8, 4, 2, 1 and the one that starts at 11 is 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

Write a function named lengthBumpy that returns the length of the bumpy sequence generated by its integer argument. The signature of the function is int lengthBumpy(int n)

Examples: lengthBumpy(10) returns 7, and lengthBumpy(11) returns 15.

You may assume that the argument n is positive and that the sequence converges to 1 without arithmetic overflow.

by java

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899