So I'm trying to sort a list of names both alphabetically and reverse alphabetically. The user would enter a list of names and once a blank entry is recorded, the program would sort the names and output it alphabetically and reverse alphabetically.
This is what I have so far:
import java.util.Scanner;
public class SortBuffer {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Text Sorting Program: (ECSE 202 - Assignment 2)");
System.out.println("Enter text to be sorted, line by line. A blank line terminates");
System.out.println("You can cut and paste into this window");
scan.nextLine();
while (!scan.nextLine().isEmpty()) {
scan.nextLine();
}
if (scan.nextLine().isEmpty()) {
System.out.println("Text in sort order:");
}
}
}
UPDATE This is what I have now (but it has errors):
import java.util.ArrayList; import java.util.Scanner;
public class SortBuffer { public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
boolean moreLines = [];
System.out.println("Text Sorting Program: (ECSE 202 - Assignment 2)");
System.out.println("Enter text to be sorted, line by line. A blank line terminates");
System.out.println("You can cut and paste into this window");
List<String> scannedLines = new ArrayList<>();
do{
String scannedLine = scan.nextLine();
boolean moreLines = !scannedLine.isEmpty();
if (moreLines){
scannedLines.add(scannedLine);
}
while (moreLines)
java.util.Collections.sort(scannedLines);
}
}}