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 Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("\\|");
- for (int i = 0; i < input.length; i++) {
- if (!input[i].trim().isEmpty()) {
- input[i] = input[i].replaceAll("\\s+", " ");
- }
- }
- List<String> nums = new ArrayList<>();
- for (int i = input.length - 1; i >= 0 ; i--) {
- nums.add(input[i].trim());
- }
- for (String num : nums) {
- System.out.print(num + " " );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment