-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArraySample.java
More file actions
73 lines (54 loc) · 1.81 KB
/
Copy pathArraySample.java
File metadata and controls
73 lines (54 loc) · 1.81 KB
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
58
59
60
61
62
63
64
65
66
import java.util.Arrays;
public class ArraySample {
public static void main(String[] args) {
int[] ns = {1, 4, 9, 16, 25};
for (int i = 0; i < ns.length; i++) {
int n = ns[i];
System.out.println(n);
}
System.out.println("------------------------------------");
for (int n : ns) {
System.out.println(n);
}
System.out.println("------------------------------------");
System.out.println(Arrays.toString(ns));
System.out.println("------------------------------------");
bubbingSort();
c1();
// ----------------------------------------------
for (String arg: args) {
System.out.println(arg);
if ("-version".equals(arg)) {
System.out.println("v 1.0");
break;
}
}
}
// todo: 冒泡排序的特点是,每一轮循环后,最大的一个数被交换到末尾,因此,下一轮循环就可以“刨除”最后的数,每一轮循环都比上一轮循环的结束位置靠前一位。
private static void bubbingSort() {
int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
System.out.printf("before sort -->>> %s\n", Arrays.toString(ns));
// todo: from small to large
for (int i = 0; i < ns.length - 1; i++) {
for (int j = 0; j < ns.length - 1 - i; j++) {
if (ns[j] > ns[j + 1]) {
int tmp = ns[j];
ns[j] = ns[j + 1];
ns[j + 1] = tmp;
}
}
}
System.out.printf("after sort -->>> %s\n", Arrays.toString(ns));
// todo: build-in sort function
int[] ns2 = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
Arrays.sort(ns2);
System.out.printf("build-in sort -->>> %s\n", Arrays.toString(ns2));
}
private static void c1() {
int[][] ns = {
{1, 2, 3, 4},
{5, 6, 7, 8}
};
System.out.println(ns.length);
}
}