一.代码
package com.zhuo.base;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
int[] a = {
1,4,5,6,72,2,2,2,25,6,7};
int[] sort = sort(a);
System.out.println(Arrays.toString(sort));
}
public static int [] sort(int[] array) {
for (int i = 0; i < array.length; i++) {
boolean flag = false;
for (int j = 0; j < array.length - 1; j++) {
if (array[j + 1] > array[j]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
flag = true;
}
}
}
return array;
}
}
二.结果显示
[72, 25, 7, 6, 6, 5, 4, 2, 2, 2, 1]
Process finished with exit code 0