We are required in our assignment to find the second smallest integer in one array recursively. However, for the sake of understanding the subject more, I want to do it iter
Try this one.
public static void main(String args[]){
int[] array = new int[]{10, 30, 15, 8, 20, 4};
int min, secondMin;
if (array[0] > array[1]){
min = array[1];
secondMin = array[0];
}
else{
min = array[0];
secondMin = array[1];
}
for (int i=2; i min) && (array[i] < secondMin)){
secondMin = array[i];
}
}
System.out.println(secondMin);
}