Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.w3c.dom.ls.LSOutput;
- import java.lang.reflect.Array;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Problem2 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] numbers = Arrays.stream(scan.nextLine().split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();
- String command = scan.nextLine();
- while (!"end".equals(command)) {
- String[] commands = command.split(" ");
- command = commands[0];
- switch (command) {
- case "swap":
- int temp = 0;
- int indexOne = Integer.parseInt(commands[1]);
- int indexTwo = Integer.parseInt(commands[2]);
- for (int i = 0; i < numbers.length ; i++) {
- if (i == indexOne || i == indexTwo){
- temp = numbers[indexOne];
- numbers[indexOne] = numbers[indexTwo];
- numbers[indexTwo] = temp;
- break;
- }
- }
- break;
- case "multiply":
- int indexOneToMultiply = Integer.parseInt(commands[1]);
- int indexTwoToMultiply = Integer.parseInt(commands[2]);
- for (int i = 0; i < numbers.length; i++) {
- if(i == indexOneToMultiply){
- temp = numbers[i] * numbers[indexTwoToMultiply];
- numbers[indexOneToMultiply] = temp;
- break;
- }else if (i == indexTwoToMultiply){
- temp = numbers[i] * numbers[indexOneToMultiply];
- numbers[indexOneToMultiply] = temp;
- break;
- }
- }
- break;
- case "decrease":
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = numbers[i] -1;
- }
- break;
- }
- command = scan.nextLine();
- }
- for (int number : numbers) {
- int lastNumber = numbers[numbers.length - 1];
- if(number == lastNumber){
- System.out.print(number);
- break;
- }
- System.out.print(number + ", ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement