當前位置:妙知谷 >

母嬰教育 >學習交流 >

java編程:用冒泡排序實現升序排列和降序排列

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;

  • 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/jy/jiaoliu/re44z.html