Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.concurrent.DelayQueue;
- public class changeName {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> names = new ArrayList<>();
- String [] parts = scanner.nextLine().split("\\s+");
- for (int i = 0; i < parts.length; i++) {
- names.add(parts[i]);
- }
- String command = scanner.next();
- while(!command.equals("Print")){
- if(command.equals("Add")){
- command = scanner.next();
- if(!names.contains(command)){
- names.add(command);
- }
- else{
- int commandIndex = scanner.nextInt();
- if(commandIndex>0 && commandIndex < names.size()){
- names.add(commandIndex,command);
- }
- }
- }
- else if(command.equals("Remove")) {
- int commandIndex = scanner.nextInt();
- if (commandIndex > 0 && commandIndex < names.size()) {
- names.remove(commandIndex);
- }
- }
- else if (command.equals("Export")) {
- int startIndex = scanner.nextInt();
- int count = scanner.nextInt();
- for (int i = startIndex; i < count ; i++) {
- if(count>names.size()){
- count = names.size();
- }
- System.out.print(names.get(i) + " ");
- }
- System.out.println();
- }
- command = scanner.next();
- }
- command = scanner.next();
- if(command.equals("Normal")){
- System.out.print("Contacts: ");
- System.out.print(String.join(" ", names));
- }
- else if(command.equals("Reversed")){
- Collections.reverse(names);
- System.out.print("Contacts: ");
- System.out.print(String.join(" ", names));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement