Skip to main content

Command Palette

Search for a command to run...

Write a Java program that identifies and print the third largest number from a given array.

Published
1 min read
Write a Java program that identifies and print the third largest number from a given array.
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

import java.util.Arrays;

public class demo {
    public static void main(String[] args) {
        int[] arr = {8, 6, 9, 2, 1, 66, 54};
        int arrLen = arr.length;

        // logic to sort the array in ascending order
        for(int i=0; i<arrLen-1; i++){
            for(int j=i+1; j<arrLen; j++){
                int temp = 0;
                if(arr[i]>arr[j]){
                    temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        /*
        // Logic to print the sorted array
        for (int a : arr){
            System.out.println(a);
        }
         */

        System.out.println("Third largest number in the array: " +arr[arrLen-3]);

    }
}

/*
Third largest number in the array: 9
*/
R

Yes for showcase it was good 😅 Like for teaching purpose

1
R

But the solution is not time efficient

1
G

Thank you for your feedback!, The approach I have used here might not be the most time-efficient for larger arrays.

But here I aimed only to showcase a basic sorting technique and find the third largest number

1

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.