In: Computer Science
Without using extra data structures, write a recursive
method
recursiveProdcutQueue ( Queue <Integer> q) in Test class
(in
stacks_queues package) that receives a queue of integers and return
the
product of the integers inside the queue. Then don’t forget to test
the
method in the main.
Make sure not to change values in queue after calling the method
use java eclipse please
`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
import java.util.LinkedList;
import java.util.Queue;
public class Test{
public static int recursiveProductQueue(Queue<Integer>
q)
{
if(q.size()==0)
{
return 1;
}
int num=q.poll();
return num*recursiveProductQueue(q);
}
public static void main(String []args){
Queue<Integer> q
= new LinkedList<>();
for (int i = 1; i <=5; i++)
q.add(i);
System.out.println(recursiveProductQueue(q));
}
}
Kindly revert for any queries
Thanks.