Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- public class List {
- public static void main (String[] args) {
- ArrayList<String> listNames;
- listNames = new ArrayList<>();
- Scanner scan = new Scanner(System.in);
- String strCheck = new String(".");
- do {
- System.out.print("Въведете име: ");
- listNames.add(0, scan.nextLine());
- }
- while (listNames.get(0).compareTo(strCheck)!=0);
- listNames.remove(".");
- if(listNames.size()>=5){
- System.out.println("Петият елемент в листа е: " + listNames.get(5));
- }
- Collections.sort(listNames);
- System.out.println(listNames);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment