Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class ListManipulation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] parts = scanner.nextLine().split(" ");
- List<String> output = new ArrayList<>();
- String input = scanner.next();
- for (int i = 0; i < parts.length; i++) {
- output.add(parts[i]);
- }
- while (!input.equals("end")) {
- String[] command = scanner.nextLine().split(" ");
- if (input.contains("Add")) {
- output.add(command[1]);
- }
- if (input.contains("Remove")) {
- output.remove(command[1]);
- }
- if (input.contains("RemoveAt")) {
- output.remove(Integer.parseInt(command[1]));
- }
- if (input.contains("Insert")) {
- output.add(Integer.parseInt(command[2]), command[1]);
- }
- input = scanner.next();
- }
- for (String s : output) {
- System.out.print(s + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment