Pages

Showing posts with label sort. Show all posts
Showing posts with label sort. Show all posts

Friday, June 29, 2012

Sorting Algorithm in java

This program will sort the given number in array.

import java.util.*;
import java.lang.*;

public class sort{
public static void main(String args[]){

int a[]={2,3,1,5,4};

for(int i=0;i<5;i++)
{
for(int j=i;j<5;j++)
{
if(a[i]>a[j])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}

}
System.out.print(" " + a[i]);
}

}
}
Read more