-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble.java
More file actions
47 lines (30 loc) · 859 Bytes
/
Bubble.java
File metadata and controls
47 lines (30 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
class Bsort{
void Bubble(int[] n){
for(int i=0;i<n.length-1;i++){
for(int j=0;j<n.length-1-i;j++){
if(n[j]>n[j+1]){
int temp = n[j];
n[j]= n[j+1];
n[j+1]=temp;
}
}
for(int i=0;i<n.length;i++){
System.out.println(n[i]);
}
}
}
public class array {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the arry size");
int n = in.nextInt();
int[] arr = new int[n];
System.out.println("Enter the array value");
for(int i=0;i<arr.length;i++){
arr[i]=in.nextInt();
}
Bsort obj =new Bsort();
obj.Bubble(arr);
}
}