You must use recursion toanswer this question no use loop Design a method called uselessSequenceGenerator to generate
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 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
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
Database Systems Design Implementation and Management
ISBN: 978-1337627900
13th edition
Authors: Carlos Coronel, Steven Morris