this program you need to implement four methods with the following signatures: printArr(int[] a) add(int[] a, int[] b) subtract(int[] a, int[] b) negate(int[] a) 1. Method printArr(a) should print out all elements of a given int array in one line.   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   4. Method negate(a)takes an int array and returns a new array in which every element is multiplied by -1.  */ public class ArrayOperations{     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("a = ");         printArr(a);//Should print each element of a (in one line)         System.out.print("b = ");         printArr(b);//Should print each element of b (in one line)         int [] arr = add(a,b);         System.out.print("a + b = ");         printArr( arr );//Should print out the array a+b         System.out.print("a - b = ");         printArr(subtract(a,b));//Should print out the array a-b         System.out.print("b - a = ");         printArr(subtract(b,a));//Should print out the array b-a          System.out.print("-a = ");         printArr(negate(a));//Should print out the array -a (negativ

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

/*
In this program you need to implement four methods with the following signatures:

printArr(int[] a)
add(int[] a, int[] b)
subtract(int[] a, int[] b)
negate(int[] a)

1. Method printArr(a) should print out all elements of a given int array in one line.
 
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
 
4. Method negate(a)takes an int array and returns a new array in which every element is multiplied by -1. 
*/

public class ArrayOperations{

    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("a = ");
        printArr(a);//Should print each element of a (in one line)
        System.out.print("b = ");
        printArr(b);//Should print each element of b (in one line)


        int [] arr = add(a,b);
        System.out.print("a + b = ");
        printArr( arr );//Should print out the array a+b

        System.out.print("a - b = ");
        printArr(subtract(a,b));//Should print out the array a-b

        System.out.print("b - a = ");
        printArr(subtract(b,a));//Should print out the array b-a 

        System.out.print("-a = ");
        printArr(negate(a));//Should print out the array -a (negative a) 


    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY