#Scanner and sorting array alphabetically
4 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @wild comet! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Looks like you aren't accounting for multiple blocks of input in your code. Write it something like this:
Scanner s = new Scanner(System.in);
while(s.hasNextLine()) {
int n = Integer.parseInt(s.nextLine());
String arr[] = new String[n];
// read in
// sort
}```
thank you so much for your reply! i managed to get the correct output by doing the following code, but its incorrect as i have to print a line between each "group". may i know how i can modify my code?