We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 50e1268 + 93d3481 commit da10a98Copy full SHA for da10a98
Algorithms/sorting/Java/Bubblesort_17251A05H5.java
@@ -0,0 +1,27 @@
1
+import java.util.Scanner;
2
+class BubbleSort{
3
+ public static void main(String args[]){
4
+ //Scanning the elements of the array
5
+ Scanner sc=new Scanner(System.in);
6
+ System.out.println("enter no. of elements");
7
+ int n=sc.nextInt();
8
+ int[] a=new int[n];
9
+ for(int i=0;i<n;i++) a[i]=sc.nextInt();
10
+ //Sorting
11
+ for (int c = 0; c < ( n - 1 ); c++) {
12
+ for (int d = 0; d < n - c - 1; d++) {
13
+ if (a[d] >a[d+1])
14
+ {
15
+ int swap= a[d];
16
+ a[d] = a[d+1];
17
+ a[d+1] = swap;
18
+ }
19
20
21
+ for(int j=0;j<a.length;j++)
22
+ System.out.print(a[j]+" ");
23
+ System.out.println();
24
+
25
26
27
+}
0 commit comments