How to find second largest number in an array in Java?

后端 未结 10 895
野的像风
野的像风 2021-01-01 05:57

I\'m just practicing some MIT java assignments. But, I\'m not sure how to find the second largest number. http://ocw.csail.mit.edu/f/13

  public class Marath         


        
10条回答
  •  伪装坚强ぢ
    2021-01-01 06:15

    int largest=time[0];
    int secondLargest=largest;
    for(int i=0;ilargest){
            secondLargest=largest;
            largest=time[i];
        }
        else if(secondLargest=largest)
            secondLargest=time[i];
    }
    return secondLargest;
    

提交回复
热议问题