7. Write a program to find the second largest and second smallest number

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] numbers={14,12,9,15,17,21,23,5,8,25};
        System.out.println("Given array: "+Arrays.toString(numbers));
        System.out.println("Second largest number: "+numbers[numbers.length-2]);
        System.out.println("Second smallest number: "+numbers[1]);

Given array: [14, 12, 9, 15, 17, 21, 23, 5, 8, 25]
Second largest number: 23
Second smallest number: 8
about author



If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

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