I have two arrays a1 = {1, 2, 3, 4, 5}
and a2 = {2, 4, 6, 8}
with an integer n = 3
. What I need to do is, using recursion, return a new array of the product of each element until reaching position marked by n. Final result should be a3 = {2, 8, 18}
.
public class Product {
public static int[] arrayProd(int [] v1, int [] v2, int n) {
if(n >= 0){
return a1[n] * a2[n];
}
}
public static void main(String [] args) {
int[] v1 = {1, 2, 3, 4, 5};
int[] v2 = {2, 4, 6, 8};
int n = 3;
}
}
It is also suggested that we should use an auxiliary method like:
private static void auxArrayProd(int [] v1, int [] v2, int [] result, int n) {
return null;
}
But I don't know how to return an array formed with integers