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