From 80e8f088d6cf59c1b5d6d256e222d2fa303f7bb5 Mon Sep 17 00:00:00 2001 From: BuddyZhang1 Date: Thu, 20 Jun 2024 17:04:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/BuddyZhang1/17122148.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 codes/BuddyZhang1/17122148.java diff --git a/codes/BuddyZhang1/17122148.java b/codes/BuddyZhang1/17122148.java new file mode 100644 index 000000000..d051cd2b1 --- /dev/null +++ b/codes/BuddyZhang1/17122148.java @@ -0,0 +1,18 @@ +** + * 冒泡排序函数 + * 将数组a按照从小到大的顺序排序 + * @param a 待排序的数组 + * @param n 待排序的数组长度 + */ +public static void bubbleSort(int[] a, int n) { + for (int i = 0; i < n - 1; i++) { // 外层循环,决定冒泡的趟数 + for (int j = 0; j < n - 1 - i; j++) { // 内层循环,决定每趟比较的次数 + if (a[j] > a[j + 1]) { // 如果当前元素大于下一个元素,则交换它们的位置 + // 交换a[j]和a[j + 1] + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +} // end -- Gitee From 8ed3f1739c50a76f0e52bed727a49183d2b6e320 Mon Sep 17 00:00:00 2001 From: BuddyZhang1 Date: Thu, 20 Jun 2024 17:18:54 +0800 Subject: [PATCH 2/2] fixup --- codes/BuddyZhang1/17122148.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/codes/BuddyZhang1/17122148.java b/codes/BuddyZhang1/17122148.java index d051cd2b1..310019105 100644 --- a/codes/BuddyZhang1/17122148.java +++ b/codes/BuddyZhang1/17122148.java @@ -4,15 +4,26 @@ * @param a 待排序的数组 * @param n 待排序的数组长度 */ -public static void bubbleSort(int[] a, int n) { - for (int i = 0; i < n - 1; i++) { // 外层循环,决定冒泡的趟数 - for (int j = 0; j < n - 1 - i; j++) { // 内层循环,决定每趟比较的次数 - if (a[j] > a[j + 1]) { // 如果当前元素大于下一个元素,则交换它们的位置 - // 交换a[j]和a[j + 1] - int temp = a[j]; - a[j] = a[j + 1]; - a[j + 1] = temp; +public class Color { + public enum color{红,蓝,绿,黄,黑}; + public static void main(String arg[]){ + int i,j,k,num=0; + color colors[]=color.values(); + System.out.println("从红,蓝,绿,黄,黑这五种颜色中取出三种不同颜色的排列有以下可能性:"); + for(i=0;i