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));