3. Write a java program to get the second largest number
Utilisateur anonyme
public class SecondLargest { public int secondLargest(int[] a) { int max = Integer.MIN_VALUE; int second = max + 1; for (int i = 0; i max) { second = max; max = a[i]; } else if (a[i] > second) { second = a[i]; } } return second; } public static void main(String[] args) { int[] a = {1, 0, -1, 6, 9, 26, 19, -8}; SecondLargest s = new SecondLargest(); System.out.println(s.secondLargest(a)); } }