Write a Program to find the second highest number from an integer array

public class Sort{
     public static void main(String []args){
        int [] array = new int [] {10,5,8,11,4,9}; 
        for(int i = 0 ; i<array.length ; i++) 
        {
            for(int j= 0 ; j<i ; j++)
            {
                if(array[i]>array[j])
                {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                    
                }
            }
            
        }
        System.out.println("Second highest number : " + array[1]);
     }
}

Output: –

Second highest number : 10

Leave a Reply

Your email address will not be published. Required fields are marked *