-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleShort.java
More file actions
34 lines (29 loc) · 886 Bytes
/
bubbleShort.java
File metadata and controls
34 lines (29 loc) · 886 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
class bubbleShort {
public static void main(String[] args) {
int[] arr = {20, 13, 10, 4, 2, 46, 8};
int size = arr.length;
int temp;
System.out.print("Before shorting: ");
for (int num : arr) {
System.out.print(num + " ");
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
System.out.println(" ");
for (int num : arr) {
System.out.print(num + " ");
}
}
System.out.println(" ");
System.out.print("After shorting: ");
for (int num : arr) {
System.out.print(num + " ");
}
}
}