Program to sort an array of integers

class Sortingofarray
{
public static void main(String args[])
{
int s;
int a[] = { 4, -5, 2, 0, 3 };

/*Bubble sort example */
for(int i=0;i<5;i++){

for(int j=i+1;j<5;j++){
if(a[i]>a[j]){
s=a[i];
a[i]=a[j];
a[j]=s;

}
else{

}

}
}
for(int i=0;i<5;i++){
System.out.println(a[i]);
}
}
}

Output:-

-5 0 2 3 4

Leave a Reply