Advertisement
veronikaaa86

06. List of Products

Jun 15th, 2022
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package list;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class P06ListOfProducts {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int n = Integer.parseInt(scanner.nextLine());
  11.  
  12. List<String> productList = new ArrayList<>();
  13. for (int i = 0; i < n; i++) {
  14. String product = scanner.nextLine();
  15.  
  16. productList.add(product);
  17. }
  18.  
  19. Collections.sort(productList);
  20.  
  21. for (int i = 0; i < n; i++) {
  22. System.out.printf("%d.%s%n", i + 1, productList.get(i));
  23. }
  24. }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement