forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.java
More file actions
30 lines (24 loc) ยท 822 Bytes
/
3.java
File metadata and controls
30 lines (24 loc) ยท 822 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
import java.util.*;
public class Main {
public static void main(String[] args) {
int n = 10;
int[] arr = {7, 5, 9, 0, 3, 1, 6, 2, 4, 8};
for (int i = 1; i < n; i++) {
// ์ธ๋ฑ์ค i๋ถํฐ 1๊น์ง ๊ฐ์ํ๋ฉฐ ๋ฐ๋ณตํ๋ ๋ฌธ๋ฒ
for (int j = i; j > 0; j--) {
// ํ ์นธ์ฉ ์ผ์ชฝ์ผ๋ก ์ด๋
if (arr[j] < arr[j - 1]) {
// ์ค์ํ(Swap)
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
// ์๊ธฐ๋ณด๋ค ์์ ๋ฐ์ดํฐ๋ฅผ ๋ง๋๋ฉด ๊ทธ ์์น์์ ๋ฉ์ถค
else break;
}
}
for(int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}