I have the task where the array resuslts" should be returned with only two values from all the array: minimum and maximum values. But the code does not do it. What's wrong? Please help me to correct the code in order to return the array with minimum and maximum values. Fill free to clarify or ask additional issues. By the conditions of the task I have not to use any other methods (Maths or strems). only loops and arrays.
public class Stat {
public static int[] getStat(int[] results) {
int min = 0;
int max = 0;
for(int i=0;i<results.length;i++){
if(results[i] < min){
min = results[i];
}
if(results[i] > max) {
max = results[i];
}
}
return new int[] { min, max };
}
}