Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (1 point) Write a method that computes the sum of the elements in an array of ints, with signature public int sum(int] a) 2.
1. (1 point) Write a method that computes the sum of the elements in an array of ints, with signature public int sum(int] a) 2. (1 point) Now, write a method that computes the sum of the elements in a List, with signature public int sum(List 1). You may assumpe the List class has been imported 3. (2 points) Write a method public void insert( int x, int[] a) that inserts element x at the first cell in the array, moving everything else out of the way by shifting it "down" one element. The last element can just be dropped. For example, suppose you had an array a of ints of length 4 that contained the following values: [10, 2, 18, 0]. After a call of insert (42, a), the new contents of the array should be [42, 10, 2, 18] 4.(1 point) How would you accomplish a similar task with a List 1? That is, what single line of code would let you insert an element at the start of the list 1? (Unlike the array method above, this will not lose the last element of the list.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started