+ 3

How to print second highest in unsorted int array?

8th Mar 2017, 1:10 PM
Sani Suryavanshi
Sani Suryavanshi - avatar
5 Respuestas
+ 11
luka nailed it!
8th Mar 2017, 7:40 PM
Tashi N
Tashi N - avatar
+ 1
Store values into two variables... int first = -1; int second = -1; int[] nums; // ... len random items from 0 to N for(int i = 0; i < len; i++) { if(nums[i] > first) { second = first; first = nums[i]; } else if(nums[i] > second) second = nums[i]; }
8th Mar 2017, 1:24 PM
AtoMX
AtoMX - avatar
+ 1
public class Program { public static void main(String[] args) { int high=0,secondhigh=0; int[] ar= {6,2,4,9,3,8}; Arrays.sort(ar);//sorting for(int n:ar) { //System.out.print(n);//sorted array } high=ar[ar.lenght-1]; System.out.print("high "+high ); secondhigh=ar[ar.lenght-2]; System.out.print("secondhigh "+secondhigh); } }
9th Mar 2017, 8:46 AM
Sani Suryavanshi
Sani Suryavanshi - avatar
0
i cnt understand ths plzz say clearly abt multidimensional array
10th Mar 2017, 1:00 PM
selva kumar
selva kumar - avatar