class Bubblesort
{
public static void main(String[] args)
{
int a[]={4,1,8,3,5};
int temp=0;
System.out.println("given array: ");
for(int j=0;j<5;j++)
{
System.out.print(a[j]);
}
System.out.println("");
System.out.println("Bubble sort for ascending order");
for(int j=0;<(a.length-1);j++)
{
for(int i=0;<(a.length-1);i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
System.out.println("the sorted array is:");
for(int k=0;k<5;k++)
{
System.out.print(a[k]);
}
}
}
aDDa For All ===> Free downloads | eBooks | Softwares | SMS | Fun | News | Codes | Techie | Music | Movies
Mar 19, 2010
JAVA Program for Bubblesort (Ascending order) of a Single Dimensional Array
Subscribe to:
Post Comments (Atom)
Output:
ReplyDeleteGiven array:
41835
Bubble sort for Ascending order
the sorted array is:
13458