Didart

List of Products

Oct 13th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.   import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class ListOfProducts {
  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> listOfProduct = new ArrayList<>();
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             String product = scanner.nextLine();
  16.  
  17.             listOfProduct.add(product);
  18.         }
  19.         Collections.sort(listOfProduct);
  20.         for (int i = 0; i < listOfProduct.size(); i++) {
  21.             System.out.printf("%d.%s%n", i + 1, listOfProduct.get(i));
  22.         }
  23.     }
  24. }
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment