Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2: Ben number (50 points) Ben had difficulty coming out with an assignment question, then he created an odd number called Ben number, which

Question 2: Ben number (50 points)

Ben had difficulty coming out with an assignment question, then he created an odd number called Ben number, which is the sum of a Ben series. Let x be the starting number and y be the bout number, in the Ben series, the x should double the value when it is an even number. In contrast, the number should be subtracted by 1 when x is an odd number. Both x and y should be greater than 0.

Example of a Ben series,

Assume the x = 3, and y = 5, then the series should be

[3, 2, 4, 8,16]. Then the Ben number should be 33 because of 3+2+4+18+16.

Thus, given the method benNumber(m,n), for all m, n > 0

benNumber(2,5) should return 62 because 2+4+8+16+32 = 62

benNumber(3,8) should return 257 because 3+2+4+8+16+32+64+128 = 257

benNumber(1,1) should return 1

Note that you can only use recursion to solve Q1 and Q2, and you cannot use any loop. You are free to add helper methods, but you are not allowed to change the method header.

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_2

Step: 3

blur-text-image_3

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

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions