Skip to content

Commit 4ba9588

Browse files
committed
Bubble Sort
1 parent 40d4257 commit 4ba9588

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

BubbleSort.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.Scanner;
2+
3+
class BubbleSort
4+
{
5+
public static void main(String[] args)
6+
{
7+
int array[]=new int[6];
8+
Scanner input=new Scanner(System.in);
9+
10+
//Input
11+
System.out.println("Enter any 6 Numbers for Unsorted Array : ");
12+
for(int i=0; i<6; i++)
13+
{
14+
array[i]=input.nextInt();
15+
}
16+
17+
//Sorting
18+
for(int i=0; i<6; i++)
19+
{
20+
for(int j=0; j<5; j++)
21+
{
22+
if(array[j]>array[j+1])
23+
{
24+
int temp=array[j];
25+
array[j]=array[j+1];
26+
array[j+1]=temp;
27+
}
28+
}
29+
}
30+
31+
//Output
32+
for(int i=0; i<6; i++)
33+
{
34+
System.out.print(array[i]+"\t");
35+
}
36+
37+
}
38+
}

0 commit comments

Comments
 (0)