Bubble Sort

import java.io.*;
class BubbleSort
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

int ARR[]=new int[10];
int i,j,temp;

System.out.println(“Enter 10 numbers in an array”);
for(i=0;i<10;i++)
{
ARR[i]=Integer.parseInt(y.readLine());
}

for(i=0;i<10-1;i++)
{
for(j=0;j<10-i-1;j++)
{
if(ARR[j]>ARR[j+1])
{
temp=ARR[j];
ARR[j]=ARR[j+1];
ARR[j+1]=temp;
}
}
}

System.out.println(“The sorted array is :”);
for(i=0;i<10;i++)
{
System.out.println(ARR[i]);
}
}
}

Leave a comment