1. import java.util.Arrays;
    2. public class Main {
    3. public static void main(String[] args) {
    4. int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
    5. // 排序前:
    6. System.out.println(Arrays.toString(ns));
    7. for (int i = 0; i < ns.length - 1; i++) {
    8. for (int j = 0; j < ns.length - i - 1; j++) {
    9. if (ns[j] > ns[j+1]) {
    10. // 交换ns[j]和ns[j+1]:
    11. int tmp = ns[j];
    12. ns[j] = ns[j+1];
    13. ns[j+1] = tmp;
    14. }
    15. }
    16. }
    17. // 排序后:
    18. System.out.println(Arrays.toString(ns));
    19. }
    20. }