Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package svephoto.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class ArrayModifier2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> elements = Arrays.stream(scanner.nextLine().split("\\s+"))
- .map(Integer::parseInt).collect(Collectors.toList());
- String command;
- while (!"end".equals(command = scanner.nextLine())) {
- String[] tokens = command.split("\\s+");
- if ("decrease".equals(tokens[0])) {
- for (int i = 0; i < elements.size(); i++) {
- int currentElementValue = elements.get(i) - 1;
- elements.set(i, currentElementValue);
- }
- }
- if ("swap".equals(tokens[0])) {
- Collections.swap(elements, Integer.parseInt(tokens[1]), Integer.parseInt(tokens[2]));
- }
- if ("multiply".equals(tokens[0])) {
- int multiplication = elements.get(Integer.parseInt(tokens[1])) * elements.get(Integer.parseInt(tokens[2]));
- elements.set(Integer.parseInt(tokens[1]), multiplication);
- }
- }
- System.out.println(formatListOfIntegers(elements));
- }
- private static String formatListOfIntegers(List<Integer> integerList) {
- return integerList.stream()
- .map(String::valueOf)
- .collect(Collectors.joining(", "));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement