Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ObrabotkaNaMasiv {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Input text: ");
- String text = scan.nextLine();
- String [] splitText = text.split(" ");
- System.out.println("Input number of commands: ");
- int n = scan.nextInt();
- System.out.println("Input type of command: ");
- for (int i = 0; i <= n; i++) {
- String command = scan.nextLine();
- if (command.equals("reverse")) {
- Collections.reverse(Arrays.asList(splitText));
- }else if (command.equals("distinct")) {
- LinkedHashSet<String> distinct = new LinkedHashSet<>(Arrays.asList(splitText));
- splitText = distinct.toArray(new String[]{});
- }else if (command.contains("Replace")) {
- splitText[Integer.parseInt(String.valueOf(command.charAt(9)))] = command.substring(11);
- }
- }
- System.out.println(Arrays.toString(splitText));
- }
- }
Add Comment
Please, Sign In to add comment