Skip to content

Commit 633ee95

Browse files
author
Tâm Lê
committed
add lab_03
1 parent 35177e4 commit 633ee95

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//int[] intArr = {1, 2, 3, 4, 5};
55
//Minimum: 1
66
//Maximum: 5
7-
public class Lab_03_21 {
7+
public class Lab_03_2 {
88

99
public static void main(String[] args) {
1010
int[] inArr = {2, 1, 3, 4, 5};

src/lab_03/Lab_03_3.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package lab_03;
2+
3+
// Requirement: Sort an integer array from min to max
4+
//Input: {12, 34, 1, 16, 28}
5+
//Expected output: {1, 12, 16, 28, 34}
6+
public class Lab_03_3 {
7+
8+
public static void main(String[] args) {
9+
int[] arr = new int[]{12, 34, 1, 16, 28};
10+
for (int i = 0; i < arr.length; i++) {
11+
for (int i1 = i + 1; i1 < arr.length; i1++) {
12+
int selectE = 0;
13+
if(arr[i] > arr[i1]){
14+
selectE = arr[i];
15+
arr[i] = arr[i1];
16+
arr[i1] = selectE;
17+
}
18+
}
19+
System.out.println(arr[i]);
20+
}
21+
}
22+
23+
}

0 commit comments

Comments
 (0)