Advertisement
Dido09

ArrayList

Feb 18th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class HouseParty {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. ArrayList<String> guestList = new ArrayList<>();
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. for (int i = 0; i < n; i++) {
  12. String[] tokens = scanner.nextLine().split("\\s+", 2);
  13. String name = tokens[0];
  14. if (tokens[1].equals("is going!")) {
  15. if (guestList.contains(name)) {
  16. System.out.println(String.format("%s is already in the list!", name));
  17. } else {
  18. guestList.add(name);
  19. }
  20. } else {
  21. if (guestList.contains(name)) {
  22. guestList.remove(name);
  23. } else {
  24. System.out.println(String.format("%s is not in the list!", name));
  25. }
  26. }
  27. }
  28. for (String guest : guestList){
  29. System.out.println(guest);
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement