Alex G Alex G - 6 months ago 3x
Java Question

Lesson 19 Project - Two Orders For Price of One - Sorting Arrays

I am using the Blue Pelican Java textbook and am stuck on the project for Lesson 19. It asks to:

Modify the code below to print two side-by-side columns. The first column should be in ascending order (like the code below will print), and the second column should be in descending order. The output should be:

Ascend   Descend
Agnes Thomas
Alfred Mary
Alvin Lee
Bernard Herman
Bill Ezra
Ezra Bill
Herman Bernard
Lee Alvin
Mary Alfred
Thomas Agnes

The code currently is:

import java.util.*;
public class Tester
public static void main(String args[])
String ss[] = {"Bill", "Mary", "Lee", "Agnes", "Alfred", "Thomas", "Alvin", "Bernard", "Ezra", "Herman"};
for(String varSs: ss)

How do I make the Descending column?

Thanks, -AJ


You could try:

Arrays.sort(ss, Collections.reverseOrder());

import java.util.Collections which you've already imported includes the reverseOrder method which will sort in descending order.