方法一、
protected int[] fun() { int[] b = { -20, 9, 7, 37, 38, 69, 89, -1, 59, 29, 0, -25, 39, 900, 22, 13, 55 }; int[] a = new int[17]; int min = 0; int max = 0; for (int i = 1; i < b.Length; i++) { if (b[min] > b[i]) { min = i; } if (b[max] < b[i]) { max = i; } } a[0] = b[min]; for (int i = 0; i < b.Length - 1; i++) { int temp = b[max]; for (int j = 0; j < b.Length; j++) { if (b[j] > a[i]) { if (temp > b[j]) temp = b[j]; } } a[i + 1] = temp; } return a; }
方法二、
int[] a = { -20, 9, 7, 37, 38, 69, 89, -1, 59, 29, 0, -25, 39, 900, 22, 13, 55 }; int[] b = new int[10]; int intTmp = a[0], intMaxNum; for (int i = 0; i < a.Length; i++) { intTmp = a[i] > intTmp ? a[i] : intTmp; } intMaxNum = intTmp; for (int j = 0; j < b.Length; j++) { for (int i = 0; i < a.Length; i++) { if (j == 0) intTmp = a[i] < intTmp ? a[i] : intTmp; else { if (a[i] > b[j - 1]) intTmp = a[i] < intTmp ? a[i] : intTmp; } } b[j] = intTmp; intTmp = intMaxNum; }