当前位置:常识集 > 母婴教育 > 学习交流 > java编程:用冒泡排序实现升序排列和降序排列
手机版

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

来源:常识集 阅读:3.46W 次

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://www.changshiji.com/myjy/jiaoliu/j266r.html

Copyright © 2024. 常识集 All right reserved. 浙ICP备20202586号-2

文字美图素材,版权属于原作者。部分文章内容由网友提供推送时因种种原因未能与原作者联系上,若涉及版权问题,敬请原作者联系我们,立即处理。