daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.text.DecimalFormat;
  2. import java.util.*;
  3. import java.util.stream.Collector;
  4. import java.util.stream.Collectors;
  5.  
  6. public class Practise {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String[] input = scanner.nextLine().split(" ");
  11.         List<Integer> nums = new ArrayList<>();
  12.  
  13.         for (String item : input) {
  14.             nums.add(Integer.parseInt(item));
  15.         }
  16.  
  17.         String command = scanner.nextLine();
  18.  
  19.         while (!"end".equals(command)) {
  20.             String[] splitCommand = command.split(" ");
  21.  
  22.             switch (splitCommand[0]) {
  23.                 case "Delete":
  24.                     int deleteElement = Integer.parseInt(splitCommand[1]);
  25.                     nums = nums.stream().filter(e -> e != deleteElement).collect(Collectors.toList());
  26.                     break;
  27.                 case "Insert":
  28.                     int element = Integer.parseInt(splitCommand[1]);
  29.                     int position = Integer.parseInt(splitCommand[2]);
  30.                     nums.add(position, element);
  31.                     break;
  32.             }
  33.             command = scanner.nextLine();
  34.         }
  35.  
  36.         for (Integer num : nums) {
  37.             System.out.print(num + " ");
  38.         }
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top