Question: JAVA /** * maxPosition returns the position of the maximum value in an array of doubles. * The first position in an array is 0
JAVA
/** * maxPosition returns the position of the maximum value in an array of doubles. * The first position in an array is 0 and the last is the list.length-1. * If the array is empty you will need to return -1. * If there are duplicates, you can return any of the indices. * * Some examples: * maxPosition(new double[] { }) is -1 * maxPosition(new double[] { -7 }) is 0 * maxPosition(new double[] { 1, -4, 7, -7, 8, 11 }) is 5 * maxPosition(new double[] { 13, -4, -7, 7, 8, 11 }) is 0 * maxPosition(new double[] { 1, -4, 11, 7, 8, 11, -9 }) is 2 or 5 */
Code I have is Below.
public static int maxPosition (double[] list) { if (list.length == 0) return 0;{ return -1; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
