/* related posts with thumb nails */

Program to implement Bubble Sort.:

import java.io.*;

class BubbleSort

{

public static void main(String as[]) throws Exception

{

int i,j,n,t,a[]=new int[10];

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

System.out.println("How many values:");

n=Integer.parseInt(br.readLine());

System.out.println("Enter Values:");

for(i=0;i

a[i]=Integer.parseInt(br.readLine());

for(i=0;i

for(j=i+1;j

if(a[i]>a[j])

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

System.out.println("After Sorting");

for(i=0;i

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

}

}

Output:

How many values: 4

Enter Values:

45

36

87

12

After Sorting:

12 36 45 87

Related Topics:

0 comments:

Post a Comment