Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java sortArrayList Code a method called sortArrayList, that takes an ArrayList of Integers as a parameter and returns another ArrayList of the same size. The

Java
sortArrayList
Code a method called sortArrayList, that takes an ArrayList of Integers as a parameter and returns another ArrayList of the same size. The method is to sort the elements in the ArrayList in descending order.
Assume the ArrayList always has more than two elements.
Example 1
ArrayList: {12, 80} return: {80, 12 }
Example 2
ArrayList: {12, 80, 109, -2} return: {109, 80, 12, -2 }
getPairWithClosestToN
Code a method called getPairWithClosestToN, that takes an array of integers and an integer, n as parameters and prints out the pair of elements in the array that have the summation closest to n. The pairs are formed by first and second elements, third and fourth elements, and so on. Assume that all elements are positive numbers.
Your code must print out a warning statement if the length of the array is smaller than 2, or is an odd number.
Example 1
array: {1, 8, 2, 4, 5, 2}, n:5
Print out: Pair that have sum closest to 5 is 2 and 4.
Example 2
array: {2}, n:5
Print out: Invalid input.

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions