The arraySum(a, b) method will add the elements a[i] + b[i] together and creates a result array of the sum.
For example, if the input arrays are:
double[] a = {1, 2};
double[] b = {1, 1};
|
the arrayAdd(a,b) call will return an array with values {2, 3}
And if the input arrays are:
double[] c = {2, 3, 4, 5};
double[] d = {-1, -1, -1, -1};
|
the arrayAdd(c,d) call will return an array with values {1, 2, 3, 4}
Use the program below to complete the assignment:
public class myProg
{
public static void main(String[] args)
{
double[] a = {1, 2};
double[] b = {1, 1};
double[] c = {2, 3, 4, 5};
double[] d = {-1, -1, -1, -1};
double[] x;
x = arraySum(a, b);
System.out.println( Arrays.toString(a) + " + " +
Arrays.toString(b) + " = " +
Arrays.toString(x) );
x = arraySum(c, d);
System.out.println( Arrays.toString(c) + " + " +
Arrays.toString(d) + " = " +
Arrays.toString(x) );
}
// Write the method arraySum() here
}
|