WAP to accept array values from user and sort them using bubble sort
18/10/2013 17:49
import java.io.*;
public class accepting
{
public static void main(String args[])throws IOException
{
System.out.println("Enter 5 numeric values");
int[]a=new int[5];
int b=a.length;
int t;
for(int l=0;l<=b-1;l++)
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.print("Enter the data of "+(l+1)+" value");
a[l]=Integer.parseInt(br.readLine());
}
for(int i=0;i<=b-1;i++)
{
for(int j=0;j<b-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println("the sorted elements are is");
for(int k=0;k<b;k++)
{
System.out.println(a[k]+" ");
}
}
}