
Sara P.
asked 07/12/20The following sorting method will rearrange all elements in the array in ascending order. Modify it so that it will sort elements in descending order. Show only the line(s) you would modify.
public static void sort(int[] values) {
int i, j, temp;
for(i=1; i<values.length; i++) {
temp = values[i];
for(j=i-1; j>=0; j--) {
if(values[j]>temp) values[j+1] = values[j];
else break;
}
values[j+1] = temp;
}
}
2 Answers By Expert Tutors
Mort M. answered 07/16/20
E.E./Computer Science graduate 10+ years Java tutoring experience
if(values[j]<temp) values[j+1] = values[j];

Patrick B. answered 07/12/20
Math and computer tutor/teacher
switch the inequality !!!
if (values[ j ] < temp )
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
you can also print the array backwards: for (int iLoop=array.length-1; iLoop>=0; iLoop--) { System.out.println(array[iLoop]); }07/12/20