Author

Author- Ram Ranjeet Kumar

Thursday, July 25, 2019

Sort Array element in Java


class SortArray
{
public static void main(String[] args)
{
int[] a={5,2,8,0,1,33,45,22,11,99};
int i,j,temp;
System.out.println("\n\t\tArray Before Swapping===>  ");
for(i=0; i<=9;i++)
{
System.out.println("\n\t\ta"+i+ "="+a[i]);
}
System.out.println("\n\t\tArray After Swapping===>  ");
for(i=0;i<=9;i++)
{
for(j=i+1;j<=9;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.println("\n\t\ta"+i+ "="+a[i]);
}
}
}

No comments:

Post a Comment