We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents a6815b1 + 76b7047 commit cd88cebCopy full SHA for cd88ceb
bubblesort.java
@@ -0,0 +1,27 @@
1
+import java.util.Scanner;
2
+public class bubblesort{
3
+ public static void main(String[] args){
4
+ Scanner sc = new Scanner(System.in);
5
+ System.out.println("Enter the number of elements");
6
+ int n = sc.nextInt();
7
+
8
+ int[] arr = new int[n];
9
+ System.out.println("Enter the elements");
10
+ for(int i = 0 ; i<n;i++){
11
+ arr[i]=sc.nextInt();
12
+ }
13
14
+ for(int j=0;j<n-i-1;j++){
15
+ if(arr[j]> arr[j+1]){
16
+ int temp = arr[j];
17
+ arr[j]= arr[j+1];
18
+ arr[j+1]= temp;
19
20
21
22
+ System.out.println("sorted array is ");
23
+ for(int i = 0;i<n;i++){
24
+ System.out.println(arr[i]+" ");
25
26
+ }}
27
0 commit comments