0% found this document useful (0 votes)
9 views6 pages

Array Sort Program

The document contains 6 Java programs: 1) to sort an array in ascending order, 2) to sort an array in descending order, 3) to find the second largest element in an array, 4) to find the third largest element in an array, 5) to find the second minimum value in an array, 6) to find the third minimum value in an array.

Uploaded by

Prasanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Array Sort Program

The document contains 6 Java programs: 1) to sort an array in ascending order, 2) to sort an array in descending order, 3) to find the second largest element in an array, 4) to find the third largest element in an array, 5) to find the second minimum value in an array, 6) to find the third minimum value in an array.

Uploaded by

Prasanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

sort the array in ascending order

public class AscendingOrder {

public static void main(String[] args) {

int[] a = {12, 14, 15, 18, 19, 13};

for (int i = 0; i < a.length - 1; i++) {

for (int j = 0; j < a.length - i - 1; j++) {

if (a[j] > a[j + 1]) {

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

for (int num : a) {

System.out.print(num + " ");

2.sort the array in decending order

import java.util.*;

public class Main {

public static void main(String[] args) {

int[] a = {12, 14, 15, 18, 19, 13};

for (int i = 0; i < a.length - 1; i++) {

for (int j = 0; j < a.length - i - 1; j++) {


if (a[j] < a[j + 1]) {

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

for (int num : a) {

System.out.print(num + " ");

3.program for find the second largest element

package Array;

import java.util.*;

public class Arraysort

public static int Secondlargest(int a[])

int temp;

int n=a.length;

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

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

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

{
temp=a[i];

a[i]=a[j];

a[j]=temp;

return a[n-2];

public static void main(String[] args)

int a[]={12,14,15,18,19,13};

System.out.println(Secondlargest(a));

4.Prgram to print the third largest number

package Array;

public class Arraysort3 {

public static int thirdlargest(int a[])

int temp;

int n=a.length;

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

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

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

temp=a[i];

a[i]=a[j];

a[j]=temp;

return a[n-3];

public static void main(String[] args)

int a[]={12,14,15,18,19,13};

System.out.println(thirdlargest(a));

5.program to print the second minimum value

package Array;

public class ArrayMin2 {

public static int min2Largest(int a[])

int temp;

int n=a.length;

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

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

if(a[i]<a[j])
{

temp=a[i];

a[i]=a[j];

a[j]=temp;

return a[n-2];

public static void main(String[] args)

int a[]={12,14,15,18,19,13};

System.out.println(min2Largest(a));

6.Program to print the third Minimum value

package Array;

public class Arraymin3 {

public static int minlargest(int a[])

int temp;

int n=a.length;

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

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

if(a[i]<a[j])
{

temp=a[i];

a[i]=a[j];

a[j]=temp;

return a[n-3];

public static void main(String[] args)

int a[]={12,14,15,18,19,13};

System.out.println(minLargest(a));

You might also like