GeorgiStGeorgiev

Untitled

Feb 24th, 2020
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4.  
  5. public class List {
  6. public static void main (String[] args) {
  7. ArrayList<String> listNames;
  8. listNames = new ArrayList<>();
  9. Scanner scan = new Scanner(System.in);
  10. String strCheck = new String(".");
  11. do {
  12. System.out.print("Въведете име: ");
  13. listNames.add(0, scan.nextLine());
  14. }
  15. while (listNames.get(0).compareTo(strCheck)!=0);
  16. listNames.remove(".");
  17. if(listNames.size()>=5){
  18. System.out.println("Петият елемент в листа е: " + listNames.get(5));
  19. }
  20. Collections.sort(listNames);
  21. System.out.println(listNames);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment