Advertisement
desislava_topuzakova

01. Unique Usernames

Jan 18th, 2022
676
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package SetsAndMapAdvanced_Exercise;
  2.  
  3. import java.util.HashSet;
  4. import java.util.LinkedHashSet;
  5. import java.util.Scanner;
  6. import java.util.Set;
  7.  
  8. public class UniqueUsernames_01 {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         Set<String> usernames = new LinkedHashSet<>(); //запазваме реда на добавяне
  12.         int countUsernames = Integer.parseInt(scanner.nextLine());
  13.         for (int count = 1; count <= countUsernames; count++) {
  14.             String username = scanner.nextLine();
  15.             usernames.add(username);
  16.         }
  17.  
  18.         usernames.forEach(System.out::println);
  19.         /*for (String username : usernames) {
  20.             System.out.println(username);
  21.         }*/
  22.     }
  23. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement