I am still somewhat new to Java programming and I have been given an assignment that asks to read names from a file and print them out that start with a letter lexicographically less than or equal to M followed by all of the names that start with a letter greater than M. Is there anyone that can help me with this?

An example would be that the file would contain

Fred Jane
Sam
Bill Nancy

and the print out on the screen would be:

1 Fred
2 Jane
3 Bill
4 Sam
5 Nancy

Recommended Answers

All 5 Replies

What do you need help with?
The Scanner class will be useful with reading the file.
The String class has methods for comparing Strings.
The ArrayList class can hold Strings that need to be saved for later.

I don't know how to sort the names in the file lexicographically, since I don't understand the sorting, I don't know where to begin with the coding for it. I'm not familiar with ArrayList, I only know how to use a simple array.

Start with a simple program that reads the names and saves them in an array.

Your sample output doesn't have the names sorted. Just separated into two groups.

The instructions do NOT say to sort the input.
I read them to say that the input is to be separated into two groups. Those before or equal and those after "M"

commented: aaaaaaaaahhhh right +1 +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.