package MaoPao;
public class MaoPao {
public static void main(String[] args) {
int[] arrey = {5, 4, 3, 1, 2, 6, 74, 45};
int tmp = 0;
for (int i = 0; i < arrey.length - 1; i++) {
for (int j = 0; j < arrey.length - i - 1; j++) {
if (arrey[j] > arrey[j + 1]) {
tmp = arrey[j];
arrey[j] = arrey[j + 1];
arrey[j + 1] = tmp;
}
}
}
for (int k = 0; k < arrey.length; k++) {
System.out.println(arrey[k]);
}
}
}
直接用sort函数也可以排序
int[] arrey = {5, 4, 3, 1, 2, 6, 74, 45};
System.out.println(Arrays.toString(arrey));
Arrays.sort(arrey);
System.out.println(Arrays.toString(arrey));