forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassendingArray.java
More file actions
57 lines (34 loc) · 826 Bytes
/
assendingArray.java
File metadata and controls
57 lines (34 loc) · 826 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
48
49
50
51
52
53
54
55
56
57
class assendingArray {
static int length;
public static void printArray(int[] array)
{
for (int i = 0; i < length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
}
public static void sortArray(int[] array)
{
int temporary = 0;
for (int i = 0; i < length; i++) {
for (int j = i + 1; j < length; j++) {
if (array[i] > array[j]) {
temporary = array[i];
array[i] = array[j];
array[j] = temporary;
}
}
}
System.out.println(
"Elements of array sorted in ascending order: ");
printArray(array);
}
public static void main(String[] args)
{
int[] array = new int[] { -5, -9, 8, 12, 1, 3 };
length = array.length;
System.out.print("Elements of original array: ");
printArray(array);
sortArray(array);
}
}