Finding the second smallest integer in array

后端 未结 19 1906
無奈伤痛
無奈伤痛 2021-01-18 05:48

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

19条回答
  •  一生所求
    2021-01-18 06:22

    class A{
        public static void main (String args[]){
            int array[]= {-5, -4, 0, 2, 10, 3, -3};
            int min;
            int second_min;
            if(array[0] array[i] && min > array[i]){
                        second_min=min;
                        min=array[i];                              
                }else  if(second_min > array[i] && min < array[i]){
                    min=min;
                    second_min=array[i];
                }
            }
            System.out.println(min);
            System.out.println(second_min);
        }
    }
    

提交回复
热议问题