学习交流

当前位置 /首页/母婴教育/学习交流/列表

java编程:用冒泡排序实现升序排列和降序排列

12,45,9,67,455,用冒泡排序实现升序排列

操作方法

(01)package huo;public class Test05 {public static void main(String[] args) ;for (int i = 0; i < th - 1; i++) {for (int j = 0; j < th - 1 - i; j++) {if (arr[j] > arr[j + 1]) {int temp;temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}tln("排序后:");for (int i = 0; i < th; i++)t(arr[i] + "t");}}

java编程:用冒泡排序实现升序排列和降序排列

特别提示

若要实现降序排列,只需将arr[j] &gt; arr[j + 1]中的&quot;&gt;&quot; 改为&quot;