- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the 3rd largest number in a Java array.
Example
Following is the required program.
public class Tester { public static int getThirdLargest(int[] a) { int temp; //sort the array for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } //return third largest element return a[a.length - 3]; } public static void main(String args[]) { int a[] = { 11,10,4, 15, 16, 13, 2 }; System.out.println("Third Largest: " +getThirdLargest(a)); } }
Output
Third largest: 13
- Related Articles
- Java program to find the 3rd largest number in an array
- Find the 3rd smallest number in a Java array.
- Find the largest number in a Java array.
- Find the 2nd largest number in a Java array.
- Java program to find the largest number in an array
- Java program to find the 2nd largest number in an array
- How to find the largest number contained in a JavaScript array?
- How Do I Find the Largest Number in a 3D JavaScript Array?
- How to Find the Largest Palindrome in an Array in Java?
- Find the smallest number in a Java array.
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- Find the 2nd smallest number in a Java array.
- Java Program to find largest prime factor of a number
- 8085 Assembly language program to find largest number in an array
- Program to Find the largest number in an array of data in 8085 Microprocessor

Advertisements