Type Here to Get Search Results !

Second Largest number find in java

0
 import java.util.*;  
 class Softwarehelp{  
 static void secondlargest(int arrys[],  
                               int arr_size)  
 {  
 int i, first, second;  
 if (arr_size < 2)  
 {  
      System.out.printf(" Invalid Input ");  
      return;  
 }  
 Arrays.sort(arrys);  
 for (i = arr_size - 2; i >= 0; i--)  
 {  
      if (arrys[i] != arrys[arr_size - 1])  
      {  
      System.out.printf("The second largest " +  
                               "element is %d\n", arrys[i]);  
      return;  
      }  
 }  
 System.out.printf("There is no second " +  
                          "largest element\n");  
 }  
 public static void main(String[] args)  
 {  
 int arrys[] = {13, 14, 15, 60, 25, 10};  
 int h = arrys.length;  
 secondlargest(arrys, h);  
 }  
 }  
Tags

Post a Comment

0 Comments

Recent-post