I'm trying to do this Java How To Program Task: "Write an appliaction that calculates the product of a series of integers that are passed to method 'product' using a variable-length argument list.
I get the error message that the method product(Integer...) in the type VarLenArgumentList is not applicable for the arguments (ArrayList). Why so, if Java treats the variable-length argument list as an array? Isn't an ArrayList an array?
What is another way of completing the task?
Scanner keyboard = new Scanner(System.in);
int flag = 0;
ArrayList<Integer> intArray = new ArrayList<>();
do
{
System.out.print("Enter a positive integer or '-1' to quit:" );
int input = keyboard.nextInt();
intArray.add(input);
} while (flag != -1);
product(intArray);
}
public static int product (Integer... numbers)
{
int total = 0;
for (Integer element : numbers)
total *= element;
return total;
}