Skip to content

Commit c3c6004

Browse files
Create assendingArray.java
1 parent cb261a8 commit c3c6004

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

assendingArray.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
class assendingArray {
3+
4+
5+
static int length;
6+
7+
8+
public static void printArray(int[] array)
9+
{
10+
11+
for (int i = 0; i < length; i++) {
12+
System.out.print(array[i] + " ");
13+
}
14+
System.out.println();
15+
}
16+
17+
18+
public static void sortArray(int[] array)
19+
{
20+
int temporary = 0;
21+
22+
23+
for (int i = 0; i < length; i++) {
24+
for (int j = i + 1; j < length; j++) {
25+
if (array[i] > array[j]) {
26+
temporary = array[i];
27+
array[i] = array[j];
28+
array[j] = temporary;
29+
}
30+
}
31+
}
32+
33+
34+
System.out.println(
35+
"Elements of array sorted in ascending order: ");
36+
printArray(array);
37+
}
38+
39+
40+
public static void main(String[] args)
41+
{
42+
43+
int[] array = new int[] { -5, -9, 8, 12, 1, 3 };
44+
45+
46+
length = array.length;
47+
48+
49+
System.out.print("Elements of original array: ");
50+
51+
52+
printArray(array);
53+
54+
55+
sortArray(array);
56+
}
57+
}

0 commit comments

Comments
 (0)