There could be various ways to do this.
- Before printing out, you sort your characters in a string alphabetically.
- You do not use a StringBuilder to store your characters, but a byte array instead. Every character is represented by a byte from 0 ('a') til 26 ('z'). You initialize the array to 0 (false). If the user tries one of the letters, you mark that one 1 (true). In the end, you iterate through the array and print only those letters that have their id marked as true. Tip: char ch; (ch - 'a') will give you their id.
Good luck