MCPcopy Create free account
hub / github.com/DuGuQiuBai/Java / ArrayDemo

Class ArrayDemo

day13/code/day13_Array_Arrays/src/cn/itcast_02/ArrayDemo.java:6–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4 * ѡ������
5 */
6public class ArrayDemo {
7 public static void main(String[] args) {
8 // ��������
9 int[] arr = { 24, 69, 80, 57, 13 };
10
11 /*
12 * // ��һ�� int x = 0; for (int y = x + 1; y < arr.length; y++) { if
13 * (arr[y] < arr[x]) { int temp = arr[x]; arr[x] = arr[y]; arr[y] =
14 * temp; } } System.out.println("��һ�αȽϣ�"); // �������� printArray(arr);
15 *
16 * // �ڶ��� x = 1; for (int y = x + 1; y < arr.length; y++) { if (arr[y] <
17 * arr[x]) { int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp; } }
18 * System.out.println("�ڶ��αȽϣ�"); // �������� printArray(arr);
19 *
20 * // ������ x = 2; for (int y = x + 1; y < arr.length; y++) { if (arr[y] <
21 * arr[x]) { int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp; } }
22 * System.out.println("�����αȽϣ�"); // �������� printArray(arr);
23 *
24 * // ���Ĵ� x = 3; for (int y = x + 1; y < arr.length; y++) { if (arr[y] <
25 * arr[x]) { int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp; } }
26 * System.out.println("���ĴαȽϣ�"); // �������� printArray(arr);
27 */
28
29 // for (int x = 0; x < arr.length - 1; x++) {
30 // for (int y = x + 1; y < arr.length; y++) {
31 // if (arr[y] < arr[x]) {
32 // int temp = arr[x];
33 // arr[x] = arr[y];
34 // arr[y] = temp;
35 // }
36 // }
37 // }
38
39 // ѡ������
40 selectSort(arr);
41 // ��������
42 printArray(arr);
43 }
44
45 // ѡ������
46 public static void selectSort(int[] arr) {
47 for (int x = 0; x < arr.length - 1; x++) {
48 for (int y = x + 1; y < arr.length; y++) {
49 if (arr[y] < arr[x]) {
50 int temp = arr[x];
51 arr[x] = arr[y];
52 arr[y] = temp;
53 }
54 }
55 }
56 }
57
58 // ��������
59 public static void printArray(int[] arr) {
60 System.out.print("[");
61 for (int x = 0; x < arr.length; x++) {
62 if (x == arr.length - 1) {
63 System.out.print(arr[x]);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected