首页 > 编程语言 > 详细

数组从小排序

时间:2021-08-03 18:48:43      阅读:25      评论:0      收藏:0      [点我收藏+]
public class array05 {
public static void main(String[] args) {
//建立一个数组
int[] a = {123, 345, 323, 678, 13, 78};
int[] sort = sort(a);
System.out.println(Arrays.toString(sort));
}

public static int[] sort(int[] array) {
int temp = 0;
for (int i = 0; i < array.length - 1; i++) {
for (int j = 0; j < array.length - 1 - i; j++) {
if (array[j + 1] < array[j]) {
temp = array[j+1];
array[j+1] = array[j ];
array[j ] = temp;
}

}
}
return array;
}
}

数组从小排序

原文:https://www.cnblogs.com/hxh123456789/p/15094834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!