-
Notifications
You must be signed in to change notification settings - Fork 28
/
sort.java
28 lines (27 loc) · 946 Bytes
/
sort.java
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
import java.util.*;
public class sort {
public static void main(String args[]) {
Scanner sn = new Scanner(System.in);
int size;
System.out.print("Enter Size:");
size = sn.nextInt();
int a[] = new int[size];
for (int i = 0; i < size; i++) {
System.out.print("Enter Element:");
a[i] = sn.nextInt();
}
for (int i = 0; i < size - 1; i++)
for (int j = 0; j < size - i - 1; j++)
if (a[j] > a[j + 1]) {
// swap arr[j+1] and arr[j]
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
System.out.print("After Swap:");
for (int i = 0; i < size; i++) {
System.out.print(a[i]);
}
System.out.println();
}
}