ArraySorting
This example we are trying to sort a hard coded array. The technique used
using two for loops we used swapping c concept to achieve this . Go through
the code you get it.
class SortingNumber
{
public static void main(String args[]) {
int a[]={35,20,10,60,5,40};
int l=a.length;
int i,j;
System.out.println("the array elements before are:");
for(i=0; i< l; i++)
System.out.print(" "+a[i]);
for(i=0; i< l;i++)
{
for(j=0;j< l;j++)
{
if(a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(" ");
System.out.println("the array elements after sorting are:");
for(i=0; i< l ;i++)
System.out.print(" "+a[i]);
}
}
After running this code you will get this kind of output.
the array elements before are:
35 20 10 60 5 40
the array elements after sorting are:
60 40 35 20 10 5
ArraySorting
Reviewed by Mukesh Jha
on
10:50 AM
Rating:
No comments:
Add your comment