java編程:用冒泡排序實現升序排列和降序排列
- 學習交流
- 關注:3.21W次
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");}}
特別提示
若要實現降序排列,只需將arr[j] > arr[j + 1]中的">" 改為"
- 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/jy/jiaoliu/re44z.html