Finding the second smallest integer in array

后端 未结 19 1943
無奈伤痛
無奈伤痛 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:36

    Try this ... First condition checks if both values are less than value in array. Second condition if value is less than small than smallest=element[i] else secondSmallest=elements[i]..

    public static void main(String[] args) 
    {
        int[] elements  = {0 , 2 , 10 , 3, -3 }; 
        int smallest = elements[0];
        int secondSmallest = 0; 
    
          for (int i = 0; i < elements.Length; i++)
            {
                if (elements[i]

提交回复
热议问题