Question: 6. a) (2 marks) Write a method that takes an array xs with at least two elements and that exchanges the first and last elements

 6. a) (2 marks) Write a method that takes an array

6. a) (2 marks) Write a method that takes an array xs with at least two elements and that exchanges the first and last elements of xs. // swaps the first and last elements of xs public void swap(int[] xs) For example, swap({2,3,4,6,9}) leaves its argument as {9,3,4,6,2}. b) (4 marks) Write a method that takes an array xs and returns a new array containing the elements of xs in reverse order. // returns a new array containing the elements of xs in reverse order public int[] reverse(int[] xs) For example, reverse({5,9,6,4}) returns (4,6,9,5). c) (4 marks) Write a method that takes an array xs and returns a new array containing the elements that have even indices in xs. // returns an array containing the elements that have even indices in xs public int[] evenlndices(int[] xs) For example, evenlndices({11,5,6,17}) returns (11,6}, and evenlndices({11,5,6,17,3}) returns (11,6,3). (Please write your essay question on a separate piece of paper)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!