package com.geminno.he0127;
import java.sql.Array;
import java.util.Arrays;
public class Test05PaiXu {
public static void main(String[] args) {
int [] a = {1,8,7,3,8,0,7,9,9,5,0};
// 比较法进行排序
for (int i = 0; i <= a.length-1; i++) {
for (int j = i+1; j <= a.length-1; j++) {
if (a[i]>a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
System.out.print(" "+a[i]);
}
// java自带方法来进行排序
// Arrays.sort(a);
// System.out.println("升序排列:");
// for (int i = 0; i < a.length; i++) {
// System.out.print(" "+a[i]);
// }
// System.out.println();
// System.out.println("降序排列:");
// for (int i = a.length-1; i >= 0; i--) {
// System.out.print(" "+a[i]);
// }
}
}
【2016.1.27】一维数组中排序输出数
最新推荐文章于 2023-04-16 15:33:12 发布