polecenie:
method that returns the position of the highest value in the array, or -1 if the array is empty.If the highest value occurs more than once, return the position of its first occurrence in the array
.
[1,2,3,0,-1] should return 2.
[1,2,2,1] should return 1.
[] should return -1.
int tmp = 0;
int tmpMax = 0;
int howManyTimesAppeared = 0;
int maxTimesAppeared = 0;
int firstAppearance = 0;
int currentAppearance = 0;
try {
if (array.length == 0) {
return -1;
} else {
for (int i = 0; i < array.length; i++) {
if(array[i]>tmp){
tmp=array[i];
howManyTimesAppeared++;
currentAppearance=i;
if(howManyTimesAppeared>maxTimesAppeared){
maxTimesAppeared=howManyTimesAppeared;
firstAppearance=currentAppearance;
}
}
}
}
} catch (UnsupportedOperationException uo) {
System.err.println("Unsupported Exception found");
}
return firstAppearance;
}
mam cos takiego i czegos mi brak :P