Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Uprajnenie;
- import java.util.LinkedHashSet;
- import java.util.Scanner;
- import java.util.Set;
- public class UniqueUsernames {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read the number of usernames as a string and convert to integer
- int n = Integer.parseInt(scanner.nextLine().trim());
- Set<String> uniqueUsernames = new LinkedHashSet<>();
- // Read usernames and add them to the set
- for (int i = 0; i < n; i++) {
- String username = scanner.nextLine().trim();
- uniqueUsernames.add(username);
- }
- // Print the unique usernames in the order of insertion
- for (String username : uniqueUsernames) {
- System.out.println(username);
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement