Wednesday, January 16, 2008

Sort an array using Bubble sort technique

import java.io.*;
class BubbleSort
{
public static void main(String args[])throws IOException
{
int x[]=new int[5];
int a=0,i=0,j=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 5 Values");
for(i=0;i<5;i++)
{
x[i]=Integer.parseInt(br.readLine());
}
for(i=0;i{
for(j=0;j{
if(x[j]>x[j+1])
{
a=x[j];
x[j]=x[j+1];
x[j+1]=a;
}
}
}
System.out.println("Result");
for(i=0;i<5;i++)
{
System.out.println(x[i]+"\t");
}
}
}

No comments: