Question: In this program you need to implement three methods with the following signatures: print(int[] a) add (int[] a, int[] b) subtract(int[l a, int[ l b)
In this program you need to implement three methods with the following signatures: print(int[] a) add (int[] a, int[] b) subtract(int[l a, int[ l b) 1. Method print (arr) should print out all elements of a given int array in one Iine. 2. Method add(a, b) should take two int arrays (assume they have the same length) and return a new array each element of which will be the sum of the corresponding elements in a and b 3. Method subtract (a, b) is similar to add(), except it returns a-b array public class ArrayOperationsf public static void main(String[] args)-{ //The main only has the testing code. //You don't have to change it. int []a={1, 2, 3, 4, 5); int [] b - (10, 1, 3, 5, 7) System.out.print(" print(a); //Should print each element of a- a (in one line) System.out.print(" print(b); //Should print each element of b (in one line) system . out.print ("a + b = "); print( add (a,b));//Should print out the array atb System . out.print ("a - b = "); print(subtract (a,b);//Should print out the array a-b System . out.print ("b - a "); print(subtract (b,a)); //Should print out the array b-a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
