import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; public class Test_A19 { public static void main(String[] args){ Integer[] numbers = {21, 25, 11, 32, 12, 35, 55, 77, 66}; Arrays.sort(numbers, Collections.reverseOrder()); ArrayList<Integer> result = new ArrayList<>(); for (int i = 0; i < numbers.length / 2; i++) { result.add(numbers[i]); // 添加最大的数 result.add(numbers[numbers.length - 1 - i]); // 添加最小的数 } // 处理剩下的单个数字 if (numbers.length % 2 != 0) { result.add(numbers[numbers.length / 2]); } System.out.println("原始数组:" + Arrays.toString(numbers)); System.out.println("按规则排序后的数组:" + result); } }标签:java,数字,剩下,最小,length,add,numbers,import,result From: https://blog.csdn.net/m0_45127365/article/details/139436483