Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class listManipulation2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> numbers = Arrays.stream(scanner.nextLine().split(" "))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- String command = scanner.nextLine();
- while (!command.equals("end")) {
- String[] comandData = command.split(" ");
- String commandType = comandData[0];
- switch (commandType) {
- case "Contains":
- int num = Integer.parseInt(comandData[1]);
- if (numbers.contains(num)) {
- System.out.println("Yes");
- } else {
- System.out.println("No such number");
- }
- break;
- case "Print":
- String type = comandData[1];
- if (type.equals("even")) {
- for (Integer number : numbers) {
- if (number % 2 == 0) {
- System.out.print(number + " ");
- }
- }
- } else if (type.equals("odd")) {
- for (Integer number : numbers) {
- if (number % 2 == 1) {
- System.out.print(number + " ");
- }
- }
- }
- command = scanner.nextLine();
- }
- }
- for (Integer number : numbers) {
- System.out.println(number);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement