Advertisement
BojidarDosev

Append Arrays

Feb 9th, 2025
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6. //TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
  7. // click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
  8. public class Main {
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scan = new Scanner(System.in);
  12.         String[] numbers = scan.nextLine().split("\\s*\\|\\s*");
  13.         int tempBrI = 0;
  14.         List<String> sorted = new ArrayList<>();
  15.         int numSize = numbers.length;
  16.  
  17.         for(int i = numSize - 1; i >= 0; i--) {
  18.             if(numbers[i].equals("|")) {
  19.                 sorted.add("");
  20.             }
  21.             else{
  22.                 sorted.add(String.valueOf(numbers[i]));
  23.             }
  24.         }
  25.  
  26.         for (int i = 0; i < sorted.size(); i++) {
  27.             System.out.print(sorted.get(i) + " ");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement