Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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