History, asked by nasa6943, 1 year ago

5.Write a program to find largest and second largest element of an array.

Answers

Answered by debjoym
1

Answer:

where to write the program?

Explanation:

in c++, java or QBASIC?

Answered by Anonymous
0

\huge\bold\pink{hello!!}

________________________________________

public class SecondLargestInArrayExample{

public static int getSecondLargest(int[] a, int total){

int temp;

for (int i = 0; i < total; i++)

{

for (int j = i + 1; j < total; j++)

{

if (a[i] > a[j])

{

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

return a[total-2];

}

public static void main(String args[]){

int a[]={1,2,5,6,3,2};

int b[]={44,66,99,77,33,22,55};

System.out.println( "Second Largest: " +getSecondLargest(a, 6 ));

System.out.println( "Second Largest: " +getSecondLargest(b, 7 ));

}

}

_______________________________________________

hope it help u.

Similar questions