Question #7252

Write the function product which consumes a list of numbers and returns the product of those numbers. Make sure you follow the design recipe!

Expert's answer

This is example on Java:

int f(LinkedList<Integer> list){

int res = 1;

for(Integer element : list){

res *= element;

}

return res;

}

//...

LinkedList<Integer> l1 = new LinkedList<Integer>();

l1.add(2);

l1.add(3);

l1.add(4);

int product = f(l1);

int f(LinkedList<Integer> list){

int res = 1;

for(Integer element : list){

res *= element;

}

return res;

}

//...

LinkedList<Integer> l1 = new LinkedList<Integer>();

l1.add(2);

l1.add(3);

l1.add(4);

int product = f(l1);

## Comments

## Leave a comment