public class Test { public static void main(String args[]) { int[] m = { 2, 8, 43, 3, 33, 1, 35, 34, 6, 9 }; int[] n = sort(m); for (int i = 0; i < m.length; i++) { System.out.println(n[i] + "\n"); } } /* 冒泡排序算法 */ public static int[] sort(int[] m) { int intLenth = m.length; /*执行intLenth次*/ for (int i = 0; i < intLenth; i++) { /*每执行一次,将最小的数排在后面*/ for (int j = 0; j < intLenth - i - 1; j++) { int a = m[j]; int b = m[j + 1]; if (a < b) { m[j] = b; m[j + 1] = a; } } } return m; } }

|