Question: Write a method named orderEnds() (including the header) that takes an array of doubles and, if the first element is larger than the last element
Write a method named orderEnds() (including the header) that takes an array of doubles and, if the first element is larger than the last element, swaps those two elements in the array. Otherwise, the method makes no changes to the array.
Your solution should not create any additional arrays or ArrayLists
For example:
if nums is {4.0, 8.9, 7.2, 1.0}, then orderEnds(nums) will change the array to be {1.0, 8.9, 7.2, 4.0}
if nums is {99.0, 96.3, 100.0}, then orderEnds(nums) will make no change to the array
if nums is {65.7}, then orderEnds(nums) will make no change to the array
if nums is { }, then orderEnds(nums) will make no change to the array
// Write the method header and implement the method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
