Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java programming recursion The starter code is given: public class A1 { public static void main(String[] args) { // System.out.println(crazySeries(10)); // System.out.println(benNumber(3, 5)); } static

Java programming recursion

The starter code is given:

public class A1 { public static void main(String[] args) { // System.out.println(crazySeries(10)); // System.out.println(benNumber(3, 5)); } static int benNumber(int a, int b) { // TODO your code goes here } public static ArrayList crazySeries(int start) { // TODO your code goes here } }

image text in transcribed

the input number must be greater than 0 , and you are not allowed to use loop here. For example, crazySeries(10)shouldreturnArrayList[10.,20.,40.,80.,160.,53.333333333333336,17.77777777777778,5.9259259259259265,1.9753086419753088]crazySeries(5)shouldreturnArrayList[5.,10.,20.,40.,80.,160.,53.333333333333336,17.77777777777778,5.9259259259259265,1.9753086419753088]crazySeries(1)shouldreturnArrayList[1.,2.,4.,8.,16.,32.,64.,128.,42.666666666666664,14.222222222222221,4.7407407407407405] 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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago