daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class kur {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.  
  13.         List<String> namesIn = new ArrayList<>();
  14.  
  15.         for (int i = 0; i < n; i++) {
  16.  
  17.             String input = scanner.nextLine();
  18.  
  19.             String[] command = input.split(" ");
  20.  
  21.  
  22.             boolean isInTheList = false;
  23.             boolean isNotInTheList = false;
  24.  
  25.             if (!"not".equalsIgnoreCase(command[2])) {
  26.  
  27.                 for (String name : namesIn) {
  28.  
  29.                     if (name.equals(command[0])) {
  30.                         isInTheList = true;
  31.                         break;
  32.                     }
  33.                 }
  34.  
  35.                 if (isInTheList) {
  36.  
  37.                     System.out.printf("%s is already in the list!%n", command[0]);
  38.  
  39.                 } else {
  40.  
  41.                     namesIn.add(command[0]);
  42.                 }
  43.             } else{
  44.  
  45.                 if (!namesIn.contains(command[0])) {
  46.  
  47.                     System.out.printf("%s is not in the list!%n", command[0]);
  48.  
  49.                 } else {
  50.  
  51.                     namesIn.remove(command[0]);
  52.                 }
  53.             }
  54.         }
  55.  
  56.  
  57.         for (String name : namesIn) {
  58.             System.out.println(name);
  59.         }
  60.  
  61.     }
  62. }
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