Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

must be in jave: also needs a tester need help d-g a) ( already completed for you ) Swap the first and last elements in

must be in jave:

also needs a tester

need help d-g

a) (already completed for you) Swap the first and last elements in the array list.

b) Shift all elements by one to the right and move the last element into the first position. For example,

1 4 9 16 25 would become 25 1 4 9 16.

c) Replace all even elements with 0.

d) Replace each element except the first and last by the larger of its two neighbors. For the example in part (b), your output would be 1 9 16 25 25.

e) Remove the middle element if the array list size is odd, or the middle two elements if the length is even. (You will need to test two different array lists here to make sure your method works on both even and odd length array lists).

f) Move all even elements to the front, otherwise preserving the order of the elements. For the example in part (b) your output should be 4 16 1 9 25

g) Return the second-largest element in the array list. (Your method should return this value, and your main method should print the value out). If your input is 3 25 50 50 22 note that 50 should be returned. 50 is both the largest and second largest value in this array list because there are 2 elements with value 50.

h) Return true if the array list is currently sorted in increasing order. (You can create a sorted ArrayList to use as input by starting with an empty Array List. Then use the add() method to add values in order one at a time). (Alternately you can use Collections.sort(); to sort your list. Use your ArrayList as a parameter to the sort() method). Make sure to test both a sorted array list and an unsorted array list as input. Your main method should print whether the array was in order or not.

i) Return true if the array list contains two adjacent duplicate elements.

j) Return true if the array list contains duplicate elements (which need not be adjacent).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions