I am trying to get at least 5 minimum values from an array of integer my code attached works but it skips few values
public static void main(String[] args) {
int array[] = {0, 1, 2, 1, 4, 5, 1, 7, 8, 1, 10, 11, 12, 13, 1, 15, 16, 17, 18, 19, 20, 2, 22, 23};
int min = 0;
int index = 0;
String output = "";
for (int x = 0; x < 5; x++){
min = array[x];
index++;
for(int i = index, limit = array.length; i < limit; ++i){
if(array[i] <= min){
min = array[i];
index = i + 1;
break;
}
}
output += index + "\t";
}
System.out.println(output);
}