【发布时间】:2021-07-14 22:06:00
【问题描述】:
我能够将矩阵中的数字从小到大排序,但我无法将它们从大到小排序。请帮忙...
int[] list = new int[4];
System.out.println("Enter the numbers of array: ");
for (int i = 0; i < list.length; i++)
list[i] = kbd.nextInt();
for (int index = 0; index < list.length; index++) {
int minIndex = index;
for (int i = index + 1; i < list.length; i++) {
if (list[i] < list[minIndex])
minIndex = i;
}
int temp = list[index];
list[index] = list[minIndex];
list[minIndex] = temp;
}
System.out.println("Numbers after sorting: ");
for (int j : list) System.out.print(j + " ");
【问题讨论】: