Here is my code:
import java.util.*;
public class Multiply {
public static void main(String[] args) {
LinkedList<Integer>num = new LinkedList<Integer>();
num.add("1");
num.add("2");
num.add("3");
num.add("4");
num.add("5");
product( num );
}
public static void product(LinkedList<Integer> list) {
int index = 0;
Iterator<Integer>productw = list.iterator();
Integer next = productw.next()
while (productw.hasNext()) {
index++;
System.out.println("The product of the numbers is = " + num);
}
}
}
Initially have a multiplication identity ( i.e., 1 ) before your while loop. And keep multiplying to it the iterator values.
Psuedo – code :
Edit 1:
The above loop assumes that the list has at least 1 element. If list has no elements, then zero must be the answer which I assume you can easily program it.