Finding the second highest number in array
        Posted  
        
            by Richard Jackson
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Richard Jackson
        
        
        
        Published on 2010-04-11T01:32:26Z
        Indexed on 
            2010/04/11
            1:43 UTC
        
        
        Read the original article
        Hit count: 428
        
java
I'm having difficulty to understand the logic behind the method to find the second highest number in array. The method used is to find the highest in the array but less than the previous highest (which has already been found). The thing that I still can't figure it out is why || highest_score == second_highest is necessary. For example I input three numbers: 98, 56, 3. Without it, both highest and second highest would be 98. Please explain.
int second highest = score[0];  
if (score[i] > second_highest && score[i] < highest_score || highest_score == second_highest)   
    second_highest = score[i];
© Stack Overflow or respective owner