Skip to main content

Posts

Showing posts with the label second largest

Second largest element

AJ Java Programs Program 5: Finding Second Largest Element in Array Ex: {2,3,4,5,3,1} are elements then 4 is second largest element Syntax: Way 1: PreDefined import java.io.*; public class FindsecondLargest {     public static void main(String[] args) {         // intialize the array values         int arr[] = { 1, 23, 47, 81, 92, 52, 48, 56, 66, 65 };         int largest = arr[0];         int secondLargest = arr[0];         // check the condition         for (int i = 0; i < arr.length; i++) {             // this condition check for largest number             if (arr[i] > largest) {                 secondLargest = largest;                 largest = arr[i];         ...