Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class listManipulation2 {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11. List<Integer> numbers = Arrays.stream(scanner.nextLine().split(" "))
  12. .map(Integer::parseInt)
  13. .collect(Collectors.toList());
  14. String command = scanner.nextLine();
  15. while (!command.equals("end")) {
  16. String[] comandData = command.split(" ");
  17. String commandType = comandData[0];
  18. switch (commandType) {
  19. case "Contains":
  20. int num = Integer.parseInt(comandData[1]);
  21. if (numbers.contains(num)) {
  22. System.out.println("Yes");
  23. } else {
  24. System.out.println("No such number");
  25. }
  26. break;
  27. case "Print":
  28. String type = comandData[1];
  29. if (type.equals("even")) {
  30. for (Integer number : numbers) {
  31. if (number % 2 == 0) {
  32. System.out.print(number + " ");
  33. }
  34. }
  35.  
  36.  
  37. } else if (type.equals("odd")) {
  38. for (Integer number : numbers) {
  39. if (number % 2 == 1) {
  40. System.out.print(number + " ");
  41. }
  42.  
  43. }
  44.  
  45. }
  46. command = scanner.nextLine();
  47. }
  48. }
  49. for (Integer number : numbers) {
  50. System.out.println(number);
  51. }
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement