Advertisement
veronikaaa86

06. List of Products

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