Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Array {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> modifier = new ArrayList<>();
- String[] strings = scanner.nextLine().split(" ");
- int temp = 0;
- String line = scanner.nextLine();
- while (!line.equals("end")){
- String[] tokens = line.split("");
- String command = tokens[0];
- switch (command) {
- case "swap":
- String parts = tokens[0];
- int firstIndex = Integer.parseInt(tokens[1]);
- int secondIndex = Integer.parseInt(tokens[2]);
- temp = firstIndex;
- firstIndex = secondIndex;
- secondIndex = temp;
- modifier.set(firstIndex, Integer.parseInt(tokens[2]));
- modifier.set(secondIndex, Integer.parseInt(tokens[1]));
- modifier.get(Integer.parseInt(tokens[1]));
- break;
- case "multiply":
- String secondParts = tokens[0];
- int indexOne = Integer.parseInt(tokens[1]);
- int indexTwo = Integer.parseInt(tokens[2]);
- long tempTwo= indexOne * indexTwo;
- modifier.get(indexOne);
- break;
- case"decrease":
- for (int i = 0; i < modifier.size() - 1 ; i++) {
- System.out.print(modifier.get(i) + "");
- }
- break;
- }
- line = scanner.nextLine();
- }
- System.out.print(modifier + " , ");
- }
- }
Add Comment
Please, Sign In to add comment