Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- public class House_Party {
- public static void main(String[] args) throws IOException {
- BufferedReader reader =
- new BufferedReader(
- new InputStreamReader(System.in));
- List<String> names = new ArrayList<>();
- System.out.println("Enter number of people ");
- int number = Integer.parseInt(reader.readLine());
- while (number -- > 0 ) {
- String[] input = reader.readLine().split("\\s+");
- if (!input[2].equals("not")) {
- if (!names.contains(input[0])) {
- names.add(input[0]);
- System.out.printf("%s is added in the list, and %s is going to the party.\n", input[0], input[0]);
- } else {
- System.out.printf("%s is in the list and %s is going to the party.\n", input[0], input[0]);
- }
- } else {
- if (names.contains(input[0])) {
- names.remove(input[0]);
- System.out.printf("%s is deleted from the list because %s is not going.\n", input[0], input[0]);
- } else {
- System.out.printf("%s is not going to the party.", input[0]);
- }
- }
- System.out.println(String.join("\n", names));
- }
- }
Add Comment
Please, Sign In to add comment