A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Find n'th highest number in a list that contains elements as random order storage


import java.util.*; class A { public static void main(String args[]) { //unsorted list int a[]={10,3,6,9,15,20,25}; //create Scanner object Scanner sc = new Scanner(System.in); //Enter n'th highest number System.out.println("Enter nth biggest"); int number=sc.nextInt(); //Sort array element by increasing order for(int i=0; i<a.length-1; i++) { for(int j=i+1; j<a.length; j++) { if(a[i]>a[j]) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; } } } //get sorted list display System.out.println("Sorted a is "); for(int i=0; i<a.length; i++) { System.out.print(a[i]+","); } //check final result System.out.println("nth highest number is "+a[number]); } }

LEARN TUTORIALS

.

.