So far, I have created 2 arrays (x and y), each with a length of 20 and are filled with random integers.
I'm trying to multiply the value of each index in one array with the value of the same index in another array, and then storing the product in a 3rd array (z).
int z[] = new int[20]; //creating array z, which will hold the products of the corresponding indexes of arrays x and y
for(int i = 0; i <z.length; i++)
{
//loop for mutliplying x and y
}
The result: if array "x" looks like {4, 8, 2, 6, ... }, and array "y" looks like {7, 5, 1, 8, ... }, array "z" should be populated with {28, 40, 2, 48, ... }
I have only been able to find examples on multiplying every single value between 2 arrays, but nothing on how to multiply corresponding indexes
Edit: Thank you, user Aominè for the solution!
The equation was simply
z[i] = x[i] * y[i];
Try something like:
for(int i = 0; i < z.length; i++) {
z[i] = x[i] * y[i];
}