This array Sorts the number in Ascending and prints the output. I wanna change it to descending, but i can't figure it out.. i tried changing the + to - but it didn't seem to work.. Can someone tip me on how to do it?
public class ArraysSorting {
public static void main(String[] args) {
int [] scores = { 5,8,2,9,3};
sortArrayDesc (scores, scores.length);
}
public static void sortArrayDesc( int [] list, int listLength) {
int index;
int smallestIndex;
int minIndex;
int temp;
for (index = 0; index < listLength - 1; index++) {
smallestIndex = index;
for (minIndex = index + 1;
minIndex < listLength; minIndex++)
if (list[minIndex] < list[smallestIndex])
smallestIndex = minIndex;
temp = list[smallestIndex];
list[smallestIndex] = list[index];
list[index] = temp;
}
//display data after sorting
System.out.print("sorted array");
for (index=0; index<listLength; index++) {
System.out.print(list[index] + ",");
}
}
}