I've been given an array. I need to get the minimum value from it, and then return the value's position in the array. I'm newer to Java, and I only really have experience in Python. Here is my code so far.
public static int minPosition (int[] list) {
int currMin = list[0];
int index = list.length-1;
int currPos = 0;
while (index >= 0){
if (currMin > list[index])
currMin = list[index];
if (currMin > list[index])
currPos = index;
index--;
}
return currPos;
}
These are my arrays that get called automatically.
minPosition(new int[] { -7 }));
minPosition(new int[] { 1, -4, -7, 7, 8, 11 }));
minPosition(new int[] { -13, -4, -7, 7, 8, 11 }));
minPosition(new int[] { 1, -4, -7, 7, 8, 11, -9 }));
Thank you in advance for the advice.