Question: You must use recursion toanswer this question no use loop Design a method called uselessSequenceGenerator to generate a useless sequence. In uselessSequenceGenerator, you must take

You must use recursion toanswer this question no use loop

Design a method called uselessSequenceGenerator to generate a useless sequence.

In uselessSequenceGenerator, you must take an integer number as the origin number and an ArrayList of the operators. Then your method should output the result according to the given operators.

For example, given the list of operators

ArrayList operators = new ArrayList<>(Arrays.asList('*', '/', '+', '-'))

We should have the following outputs:

1. uselessSequenceGenerator(5, operators) should return 7.66666666668 because 5*4/3+2-1 = 7.66666666668

2. uselessSequenceGenerator(3, operators) should return 6.0 because 3*2/1 = 6.0

3. uselessSequenceGenerator(8, operators) should return 16.5 because ((((((8*7)/6)+5)-4)*3)/2)+1 = 16.5

4. uselessSequenceGenerator(1, operators) should return 1.0

5. uselessSequenceGenerator(0, operators) should return 0.0

We can change your operators list, so for example, given ArrayList operators2 = new ArrayList<>(Arrays.asList('*', '+', '+', '/'))

We should have the following output:

1. uselessSequenceGenerator(8, operators2) should return 53.25 because ((((((8*7)+6)+5)/4)*3)+2)+1 = 53.25

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 Programming Questions!