forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.java
More file actions
35 lines (27 loc) · 813 Bytes
/
Sorting.java
File metadata and controls
35 lines (27 loc) · 813 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
// Java Program to sort an elements
// by bringing Arrays into play
// Main class
class sorting {
// Main driver method
public static void main(String[] args)
{
// Custom input array
int arr[] = { 4, 3, 2, 1 };
// Outer loop
for (int i = 0; i < arr.length; i++) {
// Inner nested loop pointing 1 index ahead
for (int j = i + 1; j < arr.length; j++) {
// Checking elements
int temp = 0;
if (arr[j] < arr[i]) {
// Swapping
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// Printing sorted array elements
System.out.print(arr[i] + " ");
}
}
}